Shared Flashcard Set

Details

rhel 5 training guide ch 06
Basic Shell Scripting
28
Computer Science
Professional
04/28/2010

Additional Computer Science Flashcards

 


 

Cards

Term
first line of a shell script
Definition
indicates what the shell script will use to run, usually it is:
#!/bin/bash
Term
you just created a text file script.sh, why won't it run
Definition
needs execute rights
Term
add execute rights to sysinfo.sh
Definition
chmod +x sysinfo.sh
Term
/usr/local/bin isn't in your user path, add it
Definition
export PATH=$PATH:/usr/local/bin
Term
how can you make it so that /usr/local/bin is always in your path
Definition
edit ~/.bash_profile to add /usr/local/bin
Term
you want to debug a sysinfo.sh, run so you can see what is going on
Definition
sh -x /usr/local/bin/sysinfo.sh
Term
you added -x to the end of the first line of sysinfo.sh, what does that do
Definition
1st line, #!/bin/bash -x debugs, prints the command, then the output
Term
edit sysinfo.sh to make it always run in debug mode
Definition
make the first line:
#!/bin/bash -x
-x for debug
Term
you are using vi, add line numbers to the screen
Definition
type:
:set nu
Term
add a local variable SYS_NAME as rhel5
Definition
SYS_NAME=rhel5
Term
echo the variable SYS_NAME in a sentence
Definition
echo "This is $SYS_NAME"
Term
you set the variable SYS_NAME in a script, the script ended. What do you get when you enter: echo $sys_NAME
Definition
nothing, the local variable was set in the script, it disappeared since it was in a sub-shell that is now closed
Term
you have two local variables, SYSNAME and OSSYS, make them global
Definition
export SYSNAME OSSYS
Term
set the variable SYS_NAME as the hostname of the system
Definition
SYS_NAME=`hostname`
use backticks (forward quotes)
Term
set OS_VER as the output from uname -r
Definition
os_ver=`uname -r`
-Confirm that this works, didn't work on Fedora 8
Term
how do you capture command output into a variable
Definition
use backticks (forward quotes) ex:
VAR1=`date`
Term
how do you use script command line arguments
Definition
$1 to $9 represent arguments 1-9
${10} arguments 10+
Term
what is the total number of arguments
Definition
$#
EXAMPLE:
TOTAL_ARGS=$#
Term
echo all the arguments passed to a script
Definition
echo $*
Term
echo the PID of the running script
Definition
echo $$
Term
echo the command or script from the script
Definition
echo $0
dollar-zero
Term
echo the command(script),
then echo arg1, then arg2
Definition
echo $0
echo $1
echo $2
Term
echo argument 12
Definition
echo ${12}
Term
echo argument 1, toss out arg1 and make arg2 the new arg1 at the same time, echo the new arg1
Definition
echo $1
shift
echo $1
Term
shift
Definition
tosses out argument1 and moves everthing down one
Term
how do you make a script interactive
Definition
read VAR1
reads the input from the user, feeds it to a variable
Term
what are some common escape sequences according to that stupid book
Definition
\c - carriage return
\a - bell
\t - tab
\n - new line
Term
let the user enter a file name so you can use it for the FILE arg - echo FILE
Definition
read FILE
echo $FILE
Supporting users have an ad free experience!