==================================================== CST8129 Review #1 - Basic Shell Concepts (Chapter 8) ==================================================== -IAN! idallen@ncf.ca This review file uses the "argv" program that displays the number of arguments passed in from the command line. 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 one $LOGNAME three EXPLAIN: what output here? $ argv "one" "$LOGNAME" "three" EXPLAIN: what output here? $ argv "one" "$LOGNAME" "three" EXPLAIN: what output here? $ argv "one $LOGNAME three" EXPLAIN: what output here? $ argv "one $LOGNAME three" EXPLAIN: what output here? $ argv 'one $LOGNAME three' EXPLAIN: what output here? $ argv 'one' '$LOGNAME' 'three' EXPLAIN: what output here? $ argv ''one'' EXPLAIN: what output here? $ argv ""''one''"" EXPLAIN: what output here? $ argv ''""''one''""'' EXPLAIN: what output here? $ argv '$LOGNAME' EXPLAIN: what output here? $ argv ''$LOGNAME'' EXPLAIN: what output here? $ argv ""''$LOGNAME''"" EXPLAIN: what output here? $ argv ''""''$LOGNAME''""'' EXPLAIN: what output here? $ argv ''one'' ''$LOGNAME'' ''three'' EXPLAIN: what output here? $ argv '''one''' '''$LOGNAME''' '''three''' EXPLAIN: what output here? $ argv ''''one'''' ''''$LOGNAME'''' ''''three'''' EXPLAIN: what output here? $ argv 'one' '$LOGNAME' 'three' EXPLAIN: what output here? $ argv 'one argument '" still one argument (no shell-visible blank)" EXPLAIN: what output here? $ argv 'one argument' "now this is a second argument (shell sees a blank)" EXPLAIN: what output here? $ argv 'one '" two "three' four'" five "six EXPLAIN: what output here? $ argv '$LOGNAME'"$LOGNAME"$LOGNAME'$LOGNAME'"$LOGNAME"$LOGNAME EXPLAIN: what output here? $ x='this contains blanks' $ argv '$x'"$x"$x'$x'"$x"$x $ argv "It's single quotes that" 'protect "all" of the metacharacters.' EXPLAIN: what output here? $ argv "It's single quotes that "'protect "all" of the metacharacters.' EXPLAIN: what output here? $ argv "It's not what you think '$LOGNAME'; look again." EXPLAIN: what output here? $ argv 'It is not what you think "$LOGNAME"; look again.' EXPLAIN: what output here? $ argv 'You must think like the '"$SHELL." EXPLAIN: what output here? $ argv 'one $LOGNAME' three ' four ' 'five'"six"seven EXPLAIN: what output here? $ 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 "$1" EXPLAIN: what output here? $ argv $1 EXPLAIN: what output here? $ argv "$3" EXPLAIN: what output here? $ argv $3 EXPLAIN: what output here? $ argv "$6" EXPLAIN: what output here? $ argv $6 EXPLAIN: what output here? $ argv "$*" EXPLAIN: what output here? $ argv $* EXPLAIN: what output here? $ argv "$@" EXPLAIN: what output here? $ argv $@ EXPLAIN: what output here? $ echo one ; date EXPLAIN: what output here? $ x=';' $ echo one $x date EXPLAIN: what output here? $ echo hello $LOGNAME there EXPLAIN: what output here? $ x='$LOGNAME' $ echo hello $x there EXPLAIN: what output here? $ echo hello $LOGNAME there EXPLAIN: what output here? $ x="$LOGNAME" $ echo hello $x there EXPLAIN: what output here? $ argv hello 'to you' there EXPLAIN: what output here? $ x="'to you'" $ argv hello $x there EXPLAIN: what output here? $ argv hello "$x" there EXPLAIN: what output here? $ argv hello "to you" there EXPLAIN: what output here? $ x='"to you"' $ argv hello $x there EXPLAIN: what output here? $ argv 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 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 $LOGNAME?" EXPLAIN: what output here? $ true && echo "See my $LOGNAME?" EXPLAIN: what output here? $ grep nosuch /etc/passwd $ echo "exit status $?" EXPLAIN: what output here? $ grep nosuch /etc/passwd && echo "See my $LOGNAME?" 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 $LOGNAME?" EXPLAIN: what output here?