======================================== CST8129 Review #1 - Basic Shell Concepts ======================================== -Ian! D. Allen idallen@idallen.ca This review file uses the "argv.sh" program that displays the number of arguments passed in from the command line. You can find a copy of this program in the course notes. To answer these questions, you must know the order in which the shell processes various special characters on the command line. Review the Notes file: expansion_order.txt --------- $ ./argv.sh one $USER three EXPLAIN: what output here? $ ./argv.sh "one" "$USER" "three" EXPLAIN: what output here? $ ./argv.sh "one" "$USER" "three" EXPLAIN: what output here? $ ./argv.sh "one $USER three" EXPLAIN: what output here? $ ./argv.sh "one $USER three" EXPLAIN: what output here? $ ./argv.sh 'one $USER three' EXPLAIN: what output here? $ ./argv.sh 'one' '$USER' 'three' EXPLAIN: what output here? $ ./argv.sh ''one'' EXPLAIN: what output here? $ ./argv.sh ""''one''"" EXPLAIN: what output here? $ ./argv.sh ''""''one''""'' EXPLAIN: what output here? $ ./argv.sh '$USER' EXPLAIN: what output here? $ ./argv.sh ''$USER'' EXPLAIN: what output here? $ ./argv.sh ""''$USER''"" EXPLAIN: what output here? $ ./argv.sh ''""''$USER''""'' EXPLAIN: what output here? $ ./argv.sh ''one'' ''$USER'' ''three'' EXPLAIN: what output here? $ ./argv.sh '''one''' '''$USER''' '''three''' EXPLAIN: what output here? $ ./argv.sh ''''one'''' ''''$USER'''' ''''three'''' EXPLAIN: what output here? $ ./argv.sh 'one' '$USER' 'three' EXPLAIN: what output here? $ ./argv.sh 'one argument '" still one argument (no shell-visible blank)" EXPLAIN: what output here? $ ./argv.sh 'one argument' "now this is a second argument (shell sees a blank)" EXPLAIN: what output here? $ ./argv.sh 'one '" two "three' four'" five "six EXPLAIN: what output here? $ ./argv.sh '$USER'"$USER"$USER'$USER'"$USER"$USER EXPLAIN: what output here? $ x='this contains blanks' $ ./argv.sh '$x'"$x"$x'$x'"$x"$x $ ./argv.sh "It's single quotes that" 'protect "all" of the metacharacters.' EXPLAIN: what output here? $ ./argv.sh "It's single quotes that "'protect "all" of the metacharacters.' EXPLAIN: what output here? $ ./argv.sh "It's not what you think '$USER'; look again." EXPLAIN: what output here? $ ./argv.sh 'It is not what you think "$USER"; look again.' EXPLAIN: what output here? $ ./argv.sh 'You must think like the '"$SHELL." EXPLAIN: what output here? $ ./argv.sh 'one $USER' three ' four ' 'five'"six"seven EXPLAIN: what output here? # Note: The following "set" command sets $1, $2, $3, etc. $ echo "The count of arguments to this $SHELL is: $#" EXPLAIN: what output here? $ set -- one two "three 3more" four "five 5more" $ echo "The count of arguments is now: $#" EXPLAIN: what output here? $ ./argv.sh "$1" EXPLAIN: what output here? $ ./argv.sh $1 EXPLAIN: what output here? $ ./argv.sh "$3" EXPLAIN: what output here? $ ./argv.sh $3 EXPLAIN: what output here? $ ./argv.sh "$6" EXPLAIN: what output here? $ ./argv.sh $6 EXPLAIN: what output here? $ ./argv.sh "$*" EXPLAIN: what output here? $ ./argv.sh $* EXPLAIN: what output here? $ ./argv.sh "$@" EXPLAIN: what output here? $ ./argv.sh $@ EXPLAIN: what output here? $ echo one ; date EXPLAIN: what output here? $ x=';' $ echo one $x date EXPLAIN: what output here? $ echo hello $USER there EXPLAIN: what output here? $ x='$USER' $ echo hello $x there EXPLAIN: what output here? $ echo hello $USER there EXPLAIN: what output here? $ x="$USER" $ echo hello $x there EXPLAIN: what output here? $ ./argv.sh hello 'to you' there EXPLAIN: what output here? $ x="'to you'" $ ./argv.sh hello $x there EXPLAIN: what output here? $ ./argv.sh hello "$x" there EXPLAIN: what output here? $ ./argv.sh hello "to you" there EXPLAIN: what output here? $ x='"to you"' $ ./argv.sh hello $x there EXPLAIN: what output here? $ ./argv.sh hello "$x" there EXPLAIN: what output here? $ echo hello && echo goodbye EXPLAIN: what output here? $ x='&&' $ echo hello $x echo goodbye EXPLAIN: what output here? $ mkdir empty $ touch empty/.12 empty/.34 empty/.56 empty/.78 $ echo "The glob pattern expands to be:" empty/??? EXPLAIN: what output here? $ echo "Try another pattern:" empty/* EXPLAIN: what output here? $ echo "Try another pattern:" empty/*[0-9][0-9] EXPLAIN: what output here? $ echo "Try another pattern:" empty/.* EXPLAIN: what output here? $ echo "Try another pattern:" empty/.[0-9]? EXPLAIN: what output here? $ echo "Combine them:" empty/.?[0-9] empty/* empty/??? EXPLAIN: what output here? $ date EXPLAIN: what output here? $ bash $ PS1='bash$ ' bash$ PATH=/etc/issue bash$ ls EXPLAIN: what output here? bash$ date EXPLAIN: what output here? bash$ who EXPLAIN: what output here? bash$ echo "The PATH '$PATH' appears to be broken." EXPLAIN: what output here? bash$ exit $ date EXPLAIN: what output here? $ mkdir empty $ touch empty/file $ ls empty EXPLAIN: what output here? $ mv ./empty/file empty/otherfile $ ls empty EXPLAIN: what output here? $ rm ./empty/./otherfile $ ls empty EXPLAIN: what output here? $ mkdir empty $ touch empty/file $ mv ./empty/file empty/../newfile $ ls empty EXPLAIN: what output here? $ echo "Where did the file go?" $ touch empty/another $ mv ./empty/another empty/../empty/mover $ ls empty EXPLAIN: what output here? $ mv empty/mover ./empty/../empty/.. $ ls ./empty EXPLAIN: what output here? $ echo "Where did the file go?" $ mkdir empty $ touch empty/one empty/.two empty/three empty/.four empty/5 $ x='empty/[o-z]* empty/[0-9] empty/.t*' $ echo '$x' EXPLAIN: what output here? $ x='empty/* empty/.*' $ echo "$x" EXPLAIN: what output here? $ mkdir empty $ cd empty $ ls EXPLAIN: what output here? $ ./argv.sh axyz bxyz cxyz dxyz '?xyz' '*xyz' ';xyz' ' xyz' EXPLAIN: what output here? $ touch axyz bxyz cxyz dxyz '?xyz' '*xyz' ';xyz' ' xyz' $ ls EXPLAIN: what output here? $ rm \?xyz $ ls EXPLAIN: what output here? $ touch axyz bxyz cxyz dxyz '?xyz' '*xyz' ';xyz' ' xyz' $ rm "?xyz" $ ls EXPLAIN: what output here? $ touch axyz bxyz cxyz dxyz '?xyz' '*xyz' ';xyz' ' xyz' $ rm '?xyz' $ ls EXPLAIN: what output here? $ touch axyz bxyz cxyz dxyz '?xyz' '*xyz' ';xyz' ' xyz' $ rm ''?xyz'' $ ls EXPLAIN: what output here? $ touch axyz bxyz cxyz dxyz '?xyz' '*xyz' ';xyz' ' xyz' $ rm ""?xyz"" $ ls EXPLAIN: what output here? $ mkdir empty $ date >empty/out $ sort empty/out >empty/out $ wc empty/out EXPLAIN: what output here? $ mkdir empty $ date >empty/out $ wc empty/out >empty/out $ wc empty/out EXPLAIN: what output here? $ false && echo "See my $USER?" EXPLAIN: what output here? $ true && echo "See my $USER?" EXPLAIN: what output here? $ grep nosuch /etc/passwd $ echo "exit status $?" EXPLAIN: what output here? $ grep nosuch /etc/passwd && echo "See my $USER?" EXPLAIN: what output here? $ grep root /etc/passwd root:x:0:0:root:/root:/bin/bash $ echo "exit status $?" EXPLAIN: what output here? $ grep root /etc/passwd && echo "See my $USER?" EXPLAIN: what output here?