3 4, 5 1
UNIX csh 2.1 bash X Window 2
grep l POSIX * more POSIX 3
UNIX. 4
first.sh #!bin/sh #first.sh #This file looks through all the files in the current #directory for the string yamada, and then prints those #files to the standard output. for file in * do if grep -q yamada $file then more $file fi done exit 0 /bin/sh first.sh 5
if, elif, for, while, until, case 6
FOO foo echo 7
bash-2.05$ salutation=hello bash-2.05$ echo $salutation bash-2.05$ salutation= Yes Dear bash-2.05$ echo $salutation bash-2.05$ salutation=7+5 bash-2.05$ echo $salutation 8
#!bin/sh myvar="hi there" echo $myvar echo "$myvar" echo '$myvar' echo \$myvar read echo Enter some text read myvar echo '$myvar' now equals $myvar exit 0 9
10
11
!/bin/sh salutation="hello" echo $salutation echo "The program $0 is now running" echo "The second parameter was $2" echo "The first parameter was $1" echo "The parameter list was $*" echo "The user's home directory is $HOME" echo "Please enter a new greeting" read salutation echo $salutation echo "The script is now complete" exit 0 12
test( [ ] ) [ ] test test if test -f fred.c then fi [ -f fred.c ] 13
test test.sh #!/bin/sh if test -f fred.c then echo "File fred.c exists." else echo "File fred.c not found." fi exit 0 14
test 15
if if condition then statements else statements fi 16
if if1.sh #!/bin/sh echo "Is it morning? Please answer yes or no" read timeofday if [ $timeofday = "yes" ]; then echo "Good morning" else echo "Good afternoon" fi exit 0 17
If if2.sh!/bin/sh echo "Is it morning? Please answer yes or no" read timeofday if [ $timeofday = "yes" ]; then echo "Good morning" elif [ $timeofday = "no" ]; then echo "Good afternoon" else echo "Sorry, $timeofday not recognized. Enter yes or no" exit 1 fi exit 0 18
If 3 if3.sh!/bin/sh echo "Is it morning? Please answer yes or no" read timeofday if [ $timeofday = "yes" ]; then echo "Good morning" elif [ $timeofday = "no" ]; then echo "Good afternoon" else echo "Sorry, $timeofday not recognized. Enter yes or no" exit 1 fi exit 0 19
for, while, case C for for variable in values do statements done 20
for 1 for1.sh #!bin/sh/ for name in aoki tokunaga ohzeki 43 do echo $name done exit 0 21
for for2.sh #!bin/sh/ for file in $(ls *.c); do echo $file done exit 0 22
While for 10 #!/bin/sh for foo in 1 2 3 4 5 6 7 8 9 10 do echo "here we go again" done exit 0 23
While while while condition do statements done 24
while while1.sh #!bin/sh echo "Enter your password" read trythis while [ "$trythis"!= "secret" ] do echo "Sorry, try again" read trythis done echo "Login succeeded." exit 0 25
while2.sh #!/bin/sh i=1 while while [ "$i" -le 10 ] do echo "Loop number : $i" i=$(($i+1)) done exit 0 26
case case case variable in pattern pattern. ) statements1;; pattern pattern. ) statements2;;.. esac 27
case case1.sh 28
case case2.sh 29
case case3.sh 30
*.txt 31
And Or AND statement1 && statement2 && statement3 false Or statement1 statement2 statement3 true 32
And Or 33
function_name( ){ statements } #!bin/sh func1.sh foo(){ echo "Function foo is executing" } echo "script starting" foo echo "script ended" exit 0 34
35
36
http://www.not-enough.org/abe/manual/unix2-ad99/array.html 37
[filename] % /bin/sh judge.sh [filename] "WARNING! No such file [filename]" "Enter Filename: " % /bin/sh judge.sh Wrong number of arguments. Usage /bin/sh judge.sh filename 38
Enter filename: datafile.txt Enter keyword: Aoki Yoshimitsu Aoki C *.c *.c.bak 39
*.c C source file *.sh Shell script file *.txt Text file else 40