basicsys@mars~/lec5>cat G1 #!/bin/bash for x in $* do echo "$x" done for x in "$*" do echo "$x" done basicsys@mars~/lec5>G1 a b c d a b c d a b c d basicsys@mars~/lec5>G1 "a b" "c d" "e f" a b c d e f a b c d e f basicsys@mars~/lec5>G1 "a b" "c d" "e f" a b c d e f a b c d e f basicsys@mars~/lec5>cat G2 #!/bin/bash for x in $@ do echo "$x" done for x in "$*" do echo "$x" done basicsys@mars~/lec5>G2 "a b" "c d" "e f" a b c d e f a b c d e f basicsys@mars~/lec5>cat G3 #!/bin/bash for x in $@ do echo "$x" done for x in "$@" do echo "$x" done basicsys@mars~/lec5>G3 "a b" "c d" "e f" a b c d e f a b c d e f basicsys@mars~/lec5>cat G4 #!/bin/bash for x in "$@" do echo "$x" done for x do echo "$x" done basicsys@mars~/lec5>G4 "a b" "c d" "e f" a b c d e f a b c d e f basicsys@mars~/lec5>cat P1 #!/bin/bash for x in $* do echo "$x" done for x in $@ do echo "$x" done for x in "$*" do echo "$x" done for x in "$@" do echo "$x" done basicsys@mars~/lec5>P1 "a b" "c d" "e f" a b c d e f a b c d e f a b c d e f a b c d e f basicsys@mars~/lec5>cat P2 #!/bin/bash echo $* echo $# shift echo $* echo $# shift echo $* echo $# basicsys@mars~/lec5>P2 a b c d a b c d 4 b c d 3 c d 2 basicsys@mars~/lec5>cat P3 #!/bin/bash s=0 while [ $# -ge 1 ] do s=$[$s+$1] shift done echo $s basicsys@mars~/lec5>P3 10 20 30 60 basicsys@mars~/lec5>cat F1 10 20 40 basicsys@mars~/lec5>P3 $(cat F1) 70 basicsys@mars~/lec5>cat F2 10 20 30 10 20 basicsys@mars~/lec5>P3 $(cat F2) 90 basicsys@mars~/lec5>cat P4 #!/bin/bash if test 5 -ge 5 then echo OK fi basicsys@mars~/lec5>P4 OK basicsys@mars~/lec5>cat P5 #!/bin/bash if [ 5 -ge 5 ] then echo OK fi basicsys@mars~/lec5>P5 OK basicsys@mars~/lec5>cat P6 #!/bin/bash if [ 5 -gt 5 ] then echo OK else echo not_OK fi basicsys@mars~/lec5>P6 not_OK basicsys@mars~/lec5>cat P7 #!/bin/bash if [ 5 -gt 5 ] then echo "5 > 5" elif [ 5 -eq 5 ] then echo "5=5" fi basicsys@mars~/lec5>P7 5=5 basicsys@mars~/lec5>cat P8 #!/bin/bash if [ 5 -gt 5 ] then echo "5 > 5" elif [ 5 -eq 8 ] then echo "5=8" fi basicsys@mars~/lec5>P8 basicsys@mars~/lec5>cat P9 #!/bin/bash if [ 5 -gt 5 ] then echo "5 > 5" elif [ 5 -eq 8 ] then echo "5=8" else echo not_OK fi basicsys@mars~/lec5>P9 not_OK basicsys@mars~/lec5>cat P10 #!/bin/bash if [ 5 -gt 5 ] then echo "5 > 5" elif [ 5 -eq 8 ] then echo "5=8" elif [ 5 -eq 5 ] then echo "5=5" fi basicsys@mars~/lec5>P10 5=5 basicsys@mars~/lec5>cat P11 #!/bin/bash if [ 5 -gt 5 -o 5 -eq 5 ] then echo "(5 > 5) | (5 = 5)" fi if [ 5 -gt 5 -a 5 -eq 5 ] then echo "(5 > 5) & (5 = 5)" fi basicsys@mars~/lec5>P11 (5 > 5) | (5 = 5) basicsys@mars~/lec5>cat P12 #!/bin/bash if [ a -gt 3 ] then echo "a > 3" fi basicsys@mars~/lec5>P12 ./P12: line 2: [: a: integer expression expected basicsys@mars~/lec5>cat P13 #!/bin/bash if [ a -eq a ] then echo "a = a" fi basicsys@mars~/lec5>P13 ./P13: line 2: [: a: integer expression expected basicsys@mars~/lec5>cat P14 #!/bin/bash if [ -e F1 ] then echo "File/Directory F1 exists" fi if [ -f F1 ] then echo "File F1 exists" fi if [ -d d1 ] then echo "directory d1 exists" fi basicsys@mars~/lec5>P14 File/Directory F1 exists File F1 exists directory d1 exists basicsys@mars~/lec5>cat P15 #!/bin/bash x=10 y=5 z=8 if [ \( $x -gt $y -o $y -gt $z \) -a \( $x -gt 0 -o $x -le then echo " ( (x > y) | (y > z) ) & (( x > 0 ) | ( x <= 8 ))" fi basicsys@mars~/lec5>cat P13.1 #!/bin/bash if [ a = a ] then echo "a = a" fi if [ 01 = 1 ] then echo "01 = 1" fi if [ 8 -ne 1 ] then echo "8 not equal 1" fi if [ ab != ac ] then echo "ab not equal ac" fi if [ ab = ac ] then echo "ab=ac" fi basicsys@mars~/lec5>P13.1 a = a 8 not equal 1 ab not equal ac basicsys@mars~/lec5>cat F1 10 10 10 29 29 ab ab ab ab 10 10 basicsys@mars~/lec5>uniq F1 10 29 ab 10 basicsys@mars~/lec5>uniq -c F1 3 10 2 29 4 ab 2 10 basicsys@mars~/lec5>uniq -d F1 10 29 ab 10 basicsys@mars~/lec5>sort F1 | uniq -c 5 10 2 29 4 ab basicsys@mars~/lec5>echo abcd | tr a-z A-Z ABCD basicsys@mars~/lec5>echo abcd | tr a-z A-Z ABCD basicsys@mars~/lec5>echo abcd | tr abcd 1-4 1234 basicsys@mars~/lec5>echo "a b c d" | tr " " "\n" a b c d basicsys@mars~/lec5>echo "a b c d" | tr -s " " "\n" a b c d basicsys@mars~/lec5>echo abcaaccdffa | tr a "\n" | wc -l 5