cd ~/it244/ex
mkdir ex26
cd ex26
foo=FOO
echo $foo
echo $foo.bar
echo $foo/bar
echo $foobar
bash
does not see the variable foo followed by the string "bar".
echo ${foo}bar
ps
echo $$The value returned by $$ is the process ID of your current shell.
ls
echo $?The command returns 0 since the previous command executed successfully.
ls xxxxx
echo $?The command returns 2 indicating that the previous command failed.
sleep 120 &
echo $!The number returned is the same as the PID that appeared on the command line when the background job was created.
nano
or an editor of your choice,
create the script positionals.shchmod 755 positionals.sh
./positionals.sh foo bar bletchYou should see
This shell script was called using ./positionals.sh This shell script was called using 3 command line arguments Here are the command line arguments: foo bar bletch Positional parameter 1: foo Positional parameter 2: bar Positional parameter 3: bletch
shift
nano
, or an editor of your choice,
create the following shell script shift.shchmod 755 shift.sh
./shift.sh foo bar bletchYou should see
foo bar bletchThe
shift
command moves each command line argument in turn
into the first positional parameter, allowing us to print each argument
until there are no more command line arguments left.
set
nano
, or an editor of your choice,
create the following shell script set.shchmod 755 set.sh
./set.shYou should see
Here are the arguments given to this script: After calling set Positional parameter 1: foo Positional parameter 2: bar Positional parameter 3: bletchEven though no arguments were given to the script at the command line,
set
created these
arguments from within the script.