120 likes | 225 Views
Shell Programming. Oleh: Idris Winarno. Topik. Hello world!!! Variables Functions Conditionals Loops Function. Percobaan 1. # vi coba1.sh #!/bin/bash echo “Hello world” #chmod u+x ./coba1.sh ./coba1.sh. Percobaan 2. # vi coba2.sh #!/bin/bash pwd ls -l date
E N D
Shell Programming Oleh: Idris Winarno
Topik • Hello world!!! • Variables • Functions • Conditionals • Loops • Function
Percobaan 1 • # vi coba1.sh • #!/bin/bash echo “Hello world” • #chmod u+x ./coba1.sh • ./coba1.sh
Percobaan 2 • # vi coba2.sh • #!/bin/bash pwd ls -l date • # chmod u+x ./coba2.sh • ./coba2.sh • Bandingkan dengan: # pwd; ls -l; date
Percobaan 3 • # vi coba3.sh • # !/bin/bash var1=“Hello world” var2=`ls` echo $var1 echo $var2 • # chmod u+x ./coba3.sh • # ./coba3.sh
Percobaan 4 • vi coba4.sh • #!/bin/bash HELLO=Hello function hello { local HELLO=World echo $HELLO } echo $HELLO hello echo $HELLO • # chmod u+x ./coba4.sh • # ./coba4.sh
Percobaan 5 • # vi coba5.sh • #!/bin/bash if [ "foo" = "foo" ]; then echo expression evaluated as true fi • # chmod u+x ./coba5.sh • ./coba5.sh
Percobaan 6 • # vi coba6.sh • #!/bin/bash T1="foo" T2="bar" if [ "$T1" = "$T2" ]; then echo expression evaluated as true else echo expression evaluated as false fi • # chmod u+x ./coba6.sh • ./coba6.sh
Percobaan 7 • vi coba7.sh • #!/bin/bash for i in $( ls ); do echo item: $i done • # chmod u+x ./coba7.sh • ./coba7.sh
Percobaan 8 • vi coba8.sh • #!/bin/bash COUNTER=0 while [ $COUNTER -lt 10 ]; do echo The counter is $COUNTER let COUNTER=COUNTER+1 done • # chmod u+x ./coba8.sh • ./coba8.sh
Percobaan 9 • # vi coba9.sh • #!/bin/bash function quit { exit } function hello { echo Hello! } hello quit echo foo • # chmod u+x ./coba9.sh • # ./coba9
Percobaan 10 • # vi coba10.sh • #!/bin/bash function quit { exit } function e { echo $1 } e Hello e World quit echo foo • # chmod u+x ./coba10.sh • ./coba10.sh