There will be no graded quiz next week.
But there will be one the following week covering the material in the previous 3 Class Quizzes.
tty ...bash performs is history expansion
$ history 5
540 cat output.txt
541 echo "Go Red Sox" > output.txt
542 cat output.txt
543 echo foo
544 history 5
$ !543
echo foo
foo
bash performs
alias substitution
$ alias ll="ls -l'
$ ll
total 2
lrwxrwxrwx 1 it244gh man 34 Sep 6 21:09 it244 -> /courses/it244/f12/ghoffman/it244gh
drwxr-xr-x 2 it244gh ugrad 512 Oct 27 09:16 workbash performs
brace expansion
$ touch foo{1,2,3,4,5}.txt
$ ls
foo1.txt foo2.txt foo3.txt foo4.txt foo5.txt
$ touch {a,ab,abc}.txt
$ ls
abc.txt ab.txt a.txt
bash performs
tilde expansion
bash sees a tilde, ~ , by itself ...bash sees a tilde, ~ , followed by a Unix user name, bash sees ~+ ...bash sees ~- ...bash performs parameter and variable expansion
$ echo $SHELL
/bin/bash
$ echo $?
0
bash performs arithmetic expansion
$ echo 5 + 4
5 + 4
$ echo $(( 5 + 4 ))
9
$ echo $a $b
5 3
$ echo $(( a * b))
15
bash performs command substitution
$(COMMAND)
$ today=$(date)
$ echo $today
Tue Oct 25 17:00:07 EDT 2011
$ ls -l `which bash`
-rwxr-xr-x 1 root root 954896 2011-03-31 17:20 /bin/bash
ls, bash first runs the command
which bash
whichls can now take /bin/bash as its argument$ args.sh foo bar bletch 3 args: [foo] [bar] [bletch]
$ args.sh 'foo bar bletch' 1 args: [foo bar bletch] $ args.sh "foo bar bletch" 1 args: [foo bar bletch]
$ args.sh $(date) 6 args: [Wed] [Apr] [12] [16:19:17] [EDT] [2017]
$ cheer="Let's go Red Sox!" $ args.sh $cheer 4 args: [Let's] [go] [Red] [Sox!]
$ args.sh $PATH 1 args: [/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/lib/oracle/12.1/client64/bin:/home/ghoffman/bin/shell:/home/ghoffman/bin/python/umb:/home/ghoffman/bin:/home/ghoffman/bin/shell:/home/ghoffman/bin/python/umb] $ IFS=: $ args.sh $PATH 15 args: [/usr/local/sbin] [/usr/local/bin] [/usr/sbin] [/usr/bin] [/sbin] [/bin] [/usr/games] [/usr/local/games] [/snap/bin] [/usr/lib/oracle/12.1/client64/bin] [/home/ghoffman/bin/shell] [/home/ghoffman/bin/python/umb] [/home/ghoffman/bin] [/home/ghoffman/bin/shell] [/home/ghoffman/bin/python/umb]
bash performs pathname expansionbash performs
process substitution
<(COMMAND)
$ diff -y <(ls -1 tia777/ce) <(ls -1 jgreen/ce)
ce1 ce1
ce10 ce10
ce11 <
ce2 ce2
ce3 ce3
ce4 ce4
ce5 ce5
ce6 ce6
ce7 ce7
ce8 ce8
ce9 ce9
ls commands ...diff to look for differences ...bash commandif statementif ... then Constructif ... then construction which has the format
if COMMAND
then
COMMAND_1
COMMAND_2
...
fi
test
$ cat if_1.sh
#! /bin/bash
##
## a shell script that demonstrates the Unix if construct
echo -n "word 1: "
read word1
echo -n "word 2: "
read word2
if test "$word1" = "$word2"
then
echo The two words match
fi
echo End of script
$ ./if_1.sh
word 1: foo
word 2: foo
The two words match
End of script
$ ./if_1.sh
word 1: foo
word 2: bar
End of script
read is a utility that takes input from standard input ...echo was used with the -n optionecho print a prompt ...readthen and fi keywordsthen must either be on a separate line from if ...
$ cat if_2.sh
#! /bin/bash
##
## a shell script that demonstrates the Unix if construct
echo -n "word 1: "
read word1
echo -n "word 2: "
read word2
if test "$word1" = "$word2" ; then
echo The two words match
fi
echo End of script
$ ./if_2.sh
word 1: foo
word 2: foo
The two words match
End of script
fi must close the conditional statementfi is if spelled backwardstesttest is a command that is often used in an if statementtest evaluates the expression that follows ...test return a value ...if statement?test it evaluates an expression ...test ...if statementif statement
$ cat if_3.sh
#! /bin/bash
##
## a shell script that demonstrates the Unix if construct
if cd ~ghoffman
then
echo was able to go to ~ghoffman
fi
echo End of script
$ ./if_3.sh
was able to go to ~ghoffman
End of script
bash, test is a built-in, a part of the shelltest is also a stand alone program
$ which test
/usr/bin/test
bash will always use the built-in version of test ...test operatorstest understands a number of operators
Operator Condition Tested -eq Two numbers are equal -ne Two numbers are not equal -ge The first number is greater than, or equal to, the second -gt The first number is greater than the second -le The first number is less than, or equal to, the second -lt The first number is less than the second
test uses the different operators when comparing strings
Operator Condition Tested = When placed between strings, are the two strings the same != When placed between strings, are the two strings not the same
test uses symbols (=) when comparing strings
Operator Condition Tested -n Whether the string given as an argument has a length greater than 0 -z Whether the string given as an argument has a length of 0
Operator Condition Tested -d Whether the argument is a directory -e Whether the argument exits as a file or directory -f Whether the argument is an ordinary file (not a directory) -r Whether the argument exists and is readable -s Whether the argument exists and has a size greater than 0 -w Whether the argument exists and is writable -x Whether the argument exists and is executable
test uses when evaluating two test expressions
Operator Condition Tested -a Logical AND meaning both expressions must be true -o Logical OR meaning either of the two expressions must be true