SlideShare a Scribd company logo
TK2123 Pemrograman Shell
Semester Genap 2015/2016
TASS, Bandung 2016
www.tass.telkomuniversity.a
c.id
Hanya dipergunakan untuk kepentingan pengajaran di lingkungan Telkom Applied Science
School (TASS)
Dasar Pemrograman Shell
Kondisi / Pencabangan
Perulangan
Berhenti / keluar blok kendali
Struktur Kendali
Alternatif proses yang akan
dieksekusi berdasar nilai
kebenaran kondisi.
Operai logika : AND, OR, NOT
Kondisi
if [ expression 1 ]
then
Statement(s) to be executed if expression 1 is true
elif [ expression 2 ]
then
Statement(s) to be executed if expression 2 is true
elif [ expression 3 ]
then
Statement(s) to be executed if expression 3 is true
else
Statement(s) to be executed if no expression is
true
fi
Sintaks
#!/bin/bash
if [ "$#" -gt 0 ] then
echo "There's Beans"
fi
if [ "$1" = "cool" ] then
echo "Cool Beans"
fi
nano latihan3a.sh
#!/bin/bash
if [ "$1" = "cool" ]
then
echo "Cool Beans"
else
echo "Not Cool Beans"
fi
nano latihan3b.sh
#!/bin/bash
if [ "$1" = "cool" ] then
echo "Cool Beans"
elif [ "$1" = "neat" ] then
echo "Neat cool"
else
echo "Not Cool Beans“
fi
nano latihan3c.sh
#!/bin/bash
if [ "$1" = "cool" ]
then
echo "Cool Beans"
else
echo "Not Cool Beans"
fi
nano latihan3d.sh
#!/bin/bash
if [ -f "$1" ] then
echo "$1 is a file"
else
echo "$1 is not a file"
fi
nano latihan3e.sh
Operasi
#!/bin/bash
a=10
b=20
if [ $a == $b ] then
echo "a is equal to b"
elif [ $a -gt $b ] then
echo "a is greater than b"
elif [ $a -lt $b ] then
echo "a is less than b"
else
echo "None of the condition met"
fi
nano latihan3f.sh
$ true
$ echo $?
#Hasilnya ?
$ false
$ echo $?
#Hasilnya ?
True and or False
$ if true; then echo "It's true."; fi
#Hasilnya ?
$ if false; then echo "It's false.";
fi
#Hasilnya ?
Banyak dipakai dengan perintah if untuk membuat
keputusan benar/salah.
Jika ekspresi bernilai benar, test keluar dengan status 0,
sebaliknya berstatus 1
Bentuk sintaksnya :
# Pertama
test expression
# Kedua
[ expression ]
Test
Ekspresi
#!/bin/bash
if [ -f .bash_profile ];then
echo "You have a .bash_profile"
else
echo "You have no .bash_profile!"
fi
nano latihan3g.sh
#!/bin/bash
if test $1 -gt 0
then
echo "$1 number is
positive"
fi
nano latihan3h.sh
Merupakan perintah yang dipakai untuk
mengakhiri skrip dan menset status exitnya.
Contoh
#Keluar skrip dengan exit status 0 (success)
exit 0
#Keluar skrip dengan exit status 1 (failure)
exit 1
Exit
$ id -u
501
$ su
Password:
# id -u
0
ID super user
#!/bin/bash
if [ $(id -u) = "0" ]; then
echo "superuser"
fi
nano latihan3i.sh
#!/bin/bash
if [ $(id -u) != "0" ]; then
echo “Harus superuser untuk menjalankan skrip ini"
exit 1
fi
nano latihan3j.sh
#!/bin/bash
if [ $# -eq 0 ]
then
echo "$0 : Ketikkkan angka integer"
exit 1
fi
if test $1 -gt 0
then
echo "$1 bilangan positif"
else
echo "$1 bilangan negatif"
fi
nano latihan3k.sh
Case – 1 (multiple if dengan
variabel tunggal)
case $variable in
match_1)
commands_to_execute_for_1
;;
match_2)
commands_to_execute_for_2
;;
match_3)
commands_to_execute_for_3
;;
.
.
.
*) (Optional - any other value)
commands_to_execute_for_no_match
;;
esac
case $variable-name in
pattern1|pattern2|pattern3)
command1
...
commandn;;
pattern4|pattern5|pattern6)
command1
...
commandn;;
pattern7|pattern8|patternN)
command1
...
commandN;;
*)
esac
Case – 2 (multiple if dengan
variabel tunggal)
#!/bin/bash
case $( arch ) in # "arch" arsitektur
mesin
# Equivalent to 'uname -m' ...
i386 ) echo "80386-based machine";;
i486 ) echo "80486-based machine";;
i586 ) echo "Pentium-based machine";;
i686 ) echo "Pentium2+-based machine";;
* ) echo "Other type of machine";;
esac
nano latihan3l.sh
#!/bin/bash
option="${1}"
case ${option} in
-f) FILE="${2}"
echo "File name is $FILE"
;;
-d) DIR="${2}"
echo "Dir name is $DIR"
;;
*)
echo "`basename ${0}`:usage: [-f file] | [-d
directory]"
exit 1 # Command to come out of the program with
status 1
;;
esac
nano latihan3m.sh
#!/bin/bash
NOW=$(date +"%a")
case $NOW in
Mon)
echo "Full backup";;
Tue|Wed|Thu|Fri)
echo "Partial backup";;
Sat|Sun)
echo "No backup";;
*) ;;
esac
nano latihan3n.sh
#!/bin/bash
# Skrip backup mysql, webserver & file-file ke tape
opt=$1
case $opt in
sql)
echo "Running mysql backup using mysqldump tool..." ;;
sync)
echo "Running backup using rsync tool..." ;;
tar)
echo "Running tape backup using tar tool..." ;;
*)
echo "Backup shell script utility"
echo "Usage: $0 {sql|sync|tar}"
echo "sql : Run mySQL backup utility."
echo "sync : Run web server backup utility."
echo "tar : Run tape backup utility." ;;
esac
nano latihan3o.sh
#!/bin/bash
echo -n "Do you agree with this? [yes or no]: "
read yno
case $yno in
[yY] | [yY][Ee][Ss] )
echo "Agreed"
;;
[nN] | [n|N][O|o] )
echo "Not agreed, can't proceed the installation";
exit 1
;;
*) echo "Invalid input"
;;
esac
nano latihan3p.sh
#!/bin/bash
case "$1" in
'start')
echo "Starting application"
/usr/bin/startpc
;;
'stop')
echo "Stopping application"
/usr/bin/stoppc
;;
'restart')
echo "Usage: $0 [start|stop]"
;;
esac
nano latihan3q.sh
!/bin/bash
# Testing ranges of characters.
echo; echo "Hit a key, then hit return."
read Keypress
case "$Keypress" in
[[:lower:]] ) echo "Lowercase letter";;
[[:upper:]] ) echo "Uppercase letter";;
[0-9] ) echo "Digit";;
* ) echo "Punctuation, whitespace, or
other";;
esac
# range karakter [square brackets],
# range POSIX [[double square brackets]]
nano latihan3r.sh
Merupakan struktur kendali yang
memungkinkan perulangan
tertentu terhadap proses.
Yang harus diperhatikan :
Kondisi berhenti harus
tercapai  jika tidak maka akan
terjadi ENDLESS LOOP (hang)
Perulangan (LOOPING)
while [ condition ]
do
command1
command2
commandN
done
Macam perulangan - 1
for { variable name } in { list }
do
command1
command2
…
commandN
done
Macam perulangan - 2
for (( expr1; expr2; expr3 ))
do
command1
command2
…
commandN
done
until [ condition ]
do
command1
command2
commandN
done
Macam perulangan - 3
#!/bin/bash
c=1
while [ $c -le 5 ]
do
echo "Welcome $c times"
(( c++ ))
done
nano latihan3s.sh
#!/bin/bash
for i in 1 2 3 4 5
do
echo "Welcome $i times"
done
nano latihan3t.sh
#!/bin/bash
for ((  i = 0 ;  i <= 5;  i+
+  ))
do
  echo "Welcome $i times"
done
nano latihan3u.sh
#!/bin/bash
i=1;
for (( ; ; ))
do
sleep $i
echo "Number: $((i++))"
done
nano latihan3v.sh
#!/bin/bash
i=1
for day in Mon Tue Wed Thu
Fri
do
echo "Weekday $((i++)) :
$day"
done
nano latihan3w.sh
#!/bin/bash
i=1
for day in "Mon Tue Wed Thu
Fri"
do
echo "Weekday $((i++)) : $day"
done
nano latihan3x.sh
#!/bin/bash
i=1
weekdays="Mon Tue Wed Thu
Fri"
for day in $weekdays
do
echo "Weekday $((i++)) :
$day"
done
nano latihan3y.sh
#!/bin/bash
for (( i=1; i <= 5; i++ ))
do
echo "Random number $i:
$RANDOM"
done
nano latihan3z0.sh
#!/bin/bash
for ((i=1, j=10; i <= 5 ; i+
+, j=j+5))
do
echo "Number $i: $j"
done
nano latihan3z1.sh
#!/bin/bash
pilih=
until [ "$pilih" = "0" ]; do
echo ""
echo "PROGRAM MENU"
echo "1 - display free disk space"
echo "2 - display free memory"
echo ""
echo "0 - exit program"
echo ""
echo -n "Enter selection: "
read pilih
echo ""
case $pilih in
1 ) df ;;
2 ) free ;;
0 ) echo “Tekan satu key. . ." ; read -n 1; exit ;;
* ) echo “Ketikkan 1, 2, atau 0"
esac
done
nano latihan3z2.sh
echo -e : enable interpretation of
backslash escapes
tput : menggerakkan kursor di layar
Warna dan kursor
Warna
#!/bin/bash
for x in 0 1 4 5 7 8 ; do
for i in `seq 30 37`; do
for a in `seq 40 47`; do
echo -ne "e[$x;$i;$a""me[$x;$i;$a""me[0;37;40m"
done
echo;
done
done
echo " ";
nano tabwarna.sh
$ PS1="[033[0;32;40mu@h:w$ ]”
$ PS1="[033[0;37;44mu@033[0;32;43mh:033[0;33;41mw$033[0m]“
$ PS1="
[033[1;34;40m[033[1;31;40mu@h:w033[1;34;40m]033[1;37;40m
$033[0;37;0m] "
Latihan
#!/bin/bash
for (( i = 1; i <= 9; i++ )) 
do
    for (( j = 1 ; j <= 9; j++ ))
    do
        tot=`expr $i + $j`
        tmp=`expr $tot % 2`
         if [ $tmp -eq 0 ]; then
             echo -e -n "033[47m “ #putih
         else
             echo -e -n "033[40m “ #Hitam
        fi
   done
  echo -e -n "033[40m" #black
 echo ""
done
nano latihan3z3.sh
- Memindahkan posisi kursor ke baris L kolom C :
033[<L>;<C>H
atau
033[<L>;<C>f
- Memindahkan kursor ke atas N baris :
033[<N>A
- Memindahkan kursor ke bawah N baris :
033[<N>B
- Memindahkan kursor maju N kolom :
033[<N>C
- Memindahkan kursor mundur N kolom :
033[<N>D
- Hapus layar, kursor ke (0,0) #sudut kiri atas
033[2J
- Hapus sampai akhir baris :
033[K
- Simpan posisi kursor :
033[s
- Restore posisi kursor :
033[u
Kursor
$ tput cup 2 3
$ tput clear
$ tput cols
$ tput lines
$ tput -S <<END
>clear
> cup 2 4
> END
$ tput setb 4
$ tput setf 4
$ tput bold
$ tput sgr0
$ echo `tput bold`guide`tput sgr0`
$ tput smul
$ tput rmul
$ echo `tput smul`guide`tput rmul`
$ tput civis
$ tput cnorm
Latihan
#!/bin/bash
clear
for (( i=1; i <= 5; i++ ));do
for (( j=1; j <= 100; j++ ));do
acakx=$(( RANDOM%20+5 ))
acaky=$(( RANDOM%70+10 ))
acakw=$(( RANDOM%8+1 ))
tput cup $acakx $acaky
echo -en "033[1;3${acakw};4${acakw}m*"
sleep 0.05
done
done
echo -en "033[0m"
nano blinkindark.sh
#!/bin/bash
for a in 0 1 4 5 7; do
echo "a=$a "
for (( f=0; f<=9; f++ )) ; do
for (( b=0; b <=9; b++ )) ; do
echo -ne "033[${a};3${f};4${b}m"
echo -ne "033[${a};3${f};4${b}m"
echo -ne "033[0m "
done
echo
done
echo
done
echo
nano tabelwarna.sh
#!/bin/bash
clear
for ((i=1;i<= 8; i++))
do
for ((j=1;j<= 8; j++))
do
total=$(($i+$j))
tmp=$(($total%2))
if [ $tmp -eq 0 ]
then
echo -e -n "033[47m $j " #ke samping
else
echo -e -n "033[40m $j " #ke samping
sleep 0.1
fi
done
echo "" #ke bawah
done
echo -e -n "033[0m"
nano chessboard.sh
#!/bin/bash
tput clear
tput cup 3 15
tput setaf 3
echo "XYX Appl. V.1"
tput sgr0
tput cup 5 17
# Set reverse video mode
tput rev
echo "M A I N - M E N U"
tput sgr0
tput cup 7 15
echo "1. User Management"
tput cup 8 15
echo "2. Service Management"
tput cup 9 15
echo "3. Process Management"
tput cup 10 15
echo "4. Backup"
tput bold
tput cup 12 15
read -p "Enter your choice [1-4] " choice
tput clear
tput sgr0
tput rc
nano menutput.sh
#!/bin/bash
echo -en "033[0m"
clear
warna=( 41 43 45 44 46 47 42 )
for (( i=0; i <= 6; i++ ))
do
tput cup 10 0
for (( j=1; j <= 20;j++ )) #ke kanan
do
echo -en "033[${warna[i]}m "
sleep 0.03
done
for (( j=10; j <= 20; j++ )) #ke bawah
do
tput cup $j 20
echo -en "033[s"
echo -e "033[${warna[i]}m "
done
for (( j=20; j >= 1; j-- )) #ke kiri
do
tput cup 20 $j
echo -en "033[s"
echo -en "033[${warna[i]}m "
sleep 0.03
done
for (( j=20; j >= 12; j-- )) #ke atas
do
tput cup $j 0
echo -en "033[s"
echo -en "033[${warna[i]}m "
sleep 0.03
done
done
echo -en "033[0m"
nano onyamuk.sh
Ad

More Related Content

What's hot (20)

The Magic Of Tie
The Magic Of TieThe Magic Of Tie
The Magic Of Tie
brian d foy
 
Unix 5 en
Unix 5 enUnix 5 en
Unix 5 en
Simonas Kareiva
 
Perl Bag of Tricks - Baltimore Perl mongers
Perl Bag of Tricks  -  Baltimore Perl mongersPerl Bag of Tricks  -  Baltimore Perl mongers
Perl Bag of Tricks - Baltimore Perl mongers
brian d foy
 
What's New in Perl? v5.10 - v5.16
What's New in Perl?  v5.10 - v5.16What's New in Perl?  v5.10 - v5.16
What's New in Perl? v5.10 - v5.16
Ricardo Signes
 
Bag of tricks
Bag of tricksBag of tricks
Bag of tricks
brian d foy
 
Parsing JSON with a single regex
Parsing JSON with a single regexParsing JSON with a single regex
Parsing JSON with a single regex
brian d foy
 
C99[2]
C99[2]C99[2]
C99[2]
guest8914af
 
The most exciting features of PHP 7.1
The most exciting features of PHP 7.1The most exciting features of PHP 7.1
The most exciting features of PHP 7.1
Zend by Rogue Wave Software
 
Groovy on the Shell
Groovy on the ShellGroovy on the Shell
Groovy on the Shell
sascha_klein
 
How to stand on the shoulders of giants
How to stand on the shoulders of giantsHow to stand on the shoulders of giants
How to stand on the shoulders of giants
Ian Barber
 
Get into the FLOW with Extbase
Get into the FLOW with ExtbaseGet into the FLOW with Extbase
Get into the FLOW with Extbase
Jochen Rau
 
Advanced modulinos
Advanced modulinosAdvanced modulinos
Advanced modulinos
brian d foy
 
Best training-in-mumbai-shell scripting
Best training-in-mumbai-shell scriptingBest training-in-mumbai-shell scripting
Best training-in-mumbai-shell scripting
vibrantuser
 
Teaching Your Machine To Find Fraudsters
Teaching Your Machine To Find FraudstersTeaching Your Machine To Find Fraudsters
Teaching Your Machine To Find Fraudsters
Ian Barber
 
Debugging: Rules And Tools - PHPTek 11 Version
Debugging: Rules And Tools - PHPTek 11 VersionDebugging: Rules And Tools - PHPTek 11 Version
Debugging: Rules And Tools - PHPTek 11 Version
Ian Barber
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
Kang-min Liu
 
Raspberry pi Part 25
Raspberry pi Part 25Raspberry pi Part 25
Raspberry pi Part 25
Techvilla
 
2-introduction_to_shell_scripting
2-introduction_to_shell_scripting2-introduction_to_shell_scripting
2-introduction_to_shell_scripting
erbipulkumar
 
Introduction to shell scripting
Introduction to shell scriptingIntroduction to shell scripting
Introduction to shell scripting
Corrado Santoro
 
News of the Symfony2 World
News of the Symfony2 WorldNews of the Symfony2 World
News of the Symfony2 World
Fabien Potencier
 
The Magic Of Tie
The Magic Of TieThe Magic Of Tie
The Magic Of Tie
brian d foy
 
Perl Bag of Tricks - Baltimore Perl mongers
Perl Bag of Tricks  -  Baltimore Perl mongersPerl Bag of Tricks  -  Baltimore Perl mongers
Perl Bag of Tricks - Baltimore Perl mongers
brian d foy
 
What's New in Perl? v5.10 - v5.16
What's New in Perl?  v5.10 - v5.16What's New in Perl?  v5.10 - v5.16
What's New in Perl? v5.10 - v5.16
Ricardo Signes
 
Parsing JSON with a single regex
Parsing JSON with a single regexParsing JSON with a single regex
Parsing JSON with a single regex
brian d foy
 
Groovy on the Shell
Groovy on the ShellGroovy on the Shell
Groovy on the Shell
sascha_klein
 
How to stand on the shoulders of giants
How to stand on the shoulders of giantsHow to stand on the shoulders of giants
How to stand on the shoulders of giants
Ian Barber
 
Get into the FLOW with Extbase
Get into the FLOW with ExtbaseGet into the FLOW with Extbase
Get into the FLOW with Extbase
Jochen Rau
 
Advanced modulinos
Advanced modulinosAdvanced modulinos
Advanced modulinos
brian d foy
 
Best training-in-mumbai-shell scripting
Best training-in-mumbai-shell scriptingBest training-in-mumbai-shell scripting
Best training-in-mumbai-shell scripting
vibrantuser
 
Teaching Your Machine To Find Fraudsters
Teaching Your Machine To Find FraudstersTeaching Your Machine To Find Fraudsters
Teaching Your Machine To Find Fraudsters
Ian Barber
 
Debugging: Rules And Tools - PHPTek 11 Version
Debugging: Rules And Tools - PHPTek 11 VersionDebugging: Rules And Tools - PHPTek 11 Version
Debugging: Rules And Tools - PHPTek 11 Version
Ian Barber
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
Kang-min Liu
 
Raspberry pi Part 25
Raspberry pi Part 25Raspberry pi Part 25
Raspberry pi Part 25
Techvilla
 
2-introduction_to_shell_scripting
2-introduction_to_shell_scripting2-introduction_to_shell_scripting
2-introduction_to_shell_scripting
erbipulkumar
 
Introduction to shell scripting
Introduction to shell scriptingIntroduction to shell scripting
Introduction to shell scripting
Corrado Santoro
 
News of the Symfony2 World
News of the Symfony2 WorldNews of the Symfony2 World
News of the Symfony2 World
Fabien Potencier
 

Viewers also liked (20)

01 tk2123 - pemrograman shell-2
01   tk2123 - pemrograman shell-201   tk2123 - pemrograman shell-2
01 tk2123 - pemrograman shell-2
Setia Juli Irzal Ismail
 
Slide minggu ke 15
Slide minggu ke 15Slide minggu ke 15
Slide minggu ke 15
Setia Juli Irzal Ismail
 
Jul gathering
Jul  gatheringJul  gathering
Jul gathering
Setia Juli Irzal Ismail
 
Slide minggu ke 13
Slide minggu ke 13Slide minggu ke 13
Slide minggu ke 13
Setia Juli Irzal Ismail
 
Minggu ke 10 (pengkodean 1)
Minggu ke 10 (pengkodean 1)Minggu ke 10 (pengkodean 1)
Minggu ke 10 (pengkodean 1)
Setia Juli Irzal Ismail
 
Slide minggu 9 (video)
Slide minggu 9 (video)Slide minggu 9 (video)
Slide minggu 9 (video)
Setia Juli Irzal Ismail
 
Slide minggu 6 jul
Slide minggu 6 julSlide minggu 6 jul
Slide minggu 6 jul
Setia Juli Irzal Ismail
 
06 tk 1073 network layer
06   tk 1073 network layer06   tk 1073 network layer
06 tk 1073 network layer
Setia Juli Irzal Ismail
 
07 tk 1073 layer transport
07   tk 1073 layer transport07   tk 1073 layer transport
07 tk 1073 layer transport
Setia Juli Irzal Ismail
 
Slide minggu ke 14
Slide minggu ke 14Slide minggu ke 14
Slide minggu ke 14
Setia Juli Irzal Ismail
 
Concurency, deadlock, starvation
Concurency, deadlock, starvationConcurency, deadlock, starvation
Concurency, deadlock, starvation
Setia Juli Irzal Ismail
 
Krs d3 tk angkatan 2014 ne
Krs d3 tk angkatan 2014 neKrs d3 tk angkatan 2014 ne
Krs d3 tk angkatan 2014 ne
Setia Juli Irzal Ismail
 
09 vpn kopie
09 vpn kopie09 vpn kopie
09 vpn kopie
Setia Juli Irzal Ismail
 
08 tk3193-authentikasi
08 tk3193-authentikasi08 tk3193-authentikasi
08 tk3193-authentikasi
Setia Juli Irzal Ismail
 
Chapter 5 firewall
Chapter 5 firewallChapter 5 firewall
Chapter 5 firewall
Setia Juli Irzal Ismail
 
10 tk3193-firewall 2
10 tk3193-firewall 210 tk3193-firewall 2
10 tk3193-firewall 2
Setia Juli Irzal Ismail
 
Vpn
VpnVpn
Vpn
Setia Juli Irzal Ismail
 
Chapter 3 footprinting
Chapter 3 footprintingChapter 3 footprinting
Chapter 3 footprinting
Setia Juli Irzal Ismail
 
Chapter 9 system penetration [compatibility mode]
Chapter 9 system penetration [compatibility mode]Chapter 9 system penetration [compatibility mode]
Chapter 9 system penetration [compatibility mode]
Setia Juli Irzal Ismail
 
Keamanan sistem operasi
Keamanan sistem operasiKeamanan sistem operasi
Keamanan sistem operasi
Setia Juli Irzal Ismail
 
Ad

Similar to 03 tk2123 - pemrograman shell-2 (20)

Unix Shell Scripting Basics
Unix Shell Scripting BasicsUnix Shell Scripting Basics
Unix Shell Scripting Basics
Dr.Ravi
 
Best training-in-mumbai-shell scripting
Best training-in-mumbai-shell scriptingBest training-in-mumbai-shell scripting
Best training-in-mumbai-shell scripting
vibrantuser
 
Perl.Hacks.On.Vim
Perl.Hacks.On.VimPerl.Hacks.On.Vim
Perl.Hacks.On.Vim
Lin Yo-An
 
10 tips for making Bash a sane programming language
10 tips for making Bash a sane programming language10 tips for making Bash a sane programming language
10 tips for making Bash a sane programming language
Yaroslav Tkachenko
 
Shell Scripting
Shell ScriptingShell Scripting
Shell Scripting
Gaurav Shinde
 
BASH Variables Part 1: Basic Interpolation
BASH Variables Part 1: Basic InterpolationBASH Variables Part 1: Basic Interpolation
BASH Variables Part 1: Basic Interpolation
Workhorse Computing
 
De 0 a 100 con Bash Shell Scripting y AWK
De 0 a 100 con Bash Shell Scripting y AWKDe 0 a 100 con Bash Shell Scripting y AWK
De 0 a 100 con Bash Shell Scripting y AWK
Adolfo Sanz De Diego
 
What is a shell script
What is a shell scriptWhat is a shell script
What is a shell script
Dr.M.Karthika parthasarathy
 
An introduction to Ruby
An introduction to RubyAn introduction to Ruby
An introduction to Ruby
Wes Oldenbeuving
 
Perl.Hacks.On.Vim Perlchina
Perl.Hacks.On.Vim PerlchinaPerl.Hacks.On.Vim Perlchina
Perl.Hacks.On.Vim Perlchina
Lin Yo-An
 
Shell programming
Shell programmingShell programming
Shell programming
Moayad Moawiah
 
Bash and regular expressions
Bash and regular expressionsBash and regular expressions
Bash and regular expressions
plarsen67
 
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaaShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
ewout2
 
Linux shell script-1
Linux shell script-1Linux shell script-1
Linux shell script-1
兎 伊藤
 
Bioinformatica p4-io
Bioinformatica p4-ioBioinformatica p4-io
Bioinformatica p4-io
Prof. Wim Van Criekinge
 
Case, Loop & Command line args un Unix
Case, Loop & Command line args un UnixCase, Loop & Command line args un Unix
Case, Loop & Command line args un Unix
Vpmv
 
Licão 12 decision loops - statement iteration
Licão 12 decision loops - statement iterationLicão 12 decision loops - statement iteration
Licão 12 decision loops - statement iteration
Acácio Oliveira
 
Good Evils In Perl
Good Evils In PerlGood Evils In Perl
Good Evils In Perl
Kang-min Liu
 
Perl.Hacks.On.Vim Perlchina
Perl.Hacks.On.Vim PerlchinaPerl.Hacks.On.Vim Perlchina
Perl.Hacks.On.Vim Perlchina
guestcf9240
 
Web 8 | Introduction to PHP
Web 8 | Introduction to PHPWeb 8 | Introduction to PHP
Web 8 | Introduction to PHP
Mohammad Imam Hossain
 
Unix Shell Scripting Basics
Unix Shell Scripting BasicsUnix Shell Scripting Basics
Unix Shell Scripting Basics
Dr.Ravi
 
Best training-in-mumbai-shell scripting
Best training-in-mumbai-shell scriptingBest training-in-mumbai-shell scripting
Best training-in-mumbai-shell scripting
vibrantuser
 
Perl.Hacks.On.Vim
Perl.Hacks.On.VimPerl.Hacks.On.Vim
Perl.Hacks.On.Vim
Lin Yo-An
 
10 tips for making Bash a sane programming language
10 tips for making Bash a sane programming language10 tips for making Bash a sane programming language
10 tips for making Bash a sane programming language
Yaroslav Tkachenko
 
BASH Variables Part 1: Basic Interpolation
BASH Variables Part 1: Basic InterpolationBASH Variables Part 1: Basic Interpolation
BASH Variables Part 1: Basic Interpolation
Workhorse Computing
 
De 0 a 100 con Bash Shell Scripting y AWK
De 0 a 100 con Bash Shell Scripting y AWKDe 0 a 100 con Bash Shell Scripting y AWK
De 0 a 100 con Bash Shell Scripting y AWK
Adolfo Sanz De Diego
 
Perl.Hacks.On.Vim Perlchina
Perl.Hacks.On.Vim PerlchinaPerl.Hacks.On.Vim Perlchina
Perl.Hacks.On.Vim Perlchina
Lin Yo-An
 
Bash and regular expressions
Bash and regular expressionsBash and regular expressions
Bash and regular expressions
plarsen67
 
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaaShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
ewout2
 
Linux shell script-1
Linux shell script-1Linux shell script-1
Linux shell script-1
兎 伊藤
 
Case, Loop & Command line args un Unix
Case, Loop & Command line args un UnixCase, Loop & Command line args un Unix
Case, Loop & Command line args un Unix
Vpmv
 
Licão 12 decision loops - statement iteration
Licão 12 decision loops - statement iterationLicão 12 decision loops - statement iteration
Licão 12 decision loops - statement iteration
Acácio Oliveira
 
Good Evils In Perl
Good Evils In PerlGood Evils In Perl
Good Evils In Perl
Kang-min Liu
 
Perl.Hacks.On.Vim Perlchina
Perl.Hacks.On.Vim PerlchinaPerl.Hacks.On.Vim Perlchina
Perl.Hacks.On.Vim Perlchina
guestcf9240
 
Ad

More from Setia Juli Irzal Ismail (20)

Minggu 2-2 Praktikum Instalasi RouterOS pada Virtualisasi-2.pdf
Minggu 2-2  Praktikum Instalasi RouterOS pada Virtualisasi-2.pdfMinggu 2-2  Praktikum Instalasi RouterOS pada Virtualisasi-2.pdf
Minggu 2-2 Praktikum Instalasi RouterOS pada Virtualisasi-2.pdf
Setia Juli Irzal Ismail
 
Introduction to self-Supervised learning - kuliah machine learning STEI ITB
Introduction to self-Supervised learning - kuliah machine learning STEI ITBIntroduction to self-Supervised learning - kuliah machine learning STEI ITB
Introduction to self-Supervised learning - kuliah machine learning STEI ITB
Setia Juli Irzal Ismail
 
Materi lanjutan Deep Learning S1 Telekomunikasi - STEI ITB
Materi lanjutan Deep Learning  S1 Telekomunikasi - STEI ITBMateri lanjutan Deep Learning  S1 Telekomunikasi - STEI ITB
Materi lanjutan Deep Learning S1 Telekomunikasi - STEI ITB
Setia Juli Irzal Ismail
 
Slide materi pengantar kuliah Deep Learning STEI ITB
Slide materi pengantar kuliah Deep Learning STEI ITBSlide materi pengantar kuliah Deep Learning STEI ITB
Slide materi pengantar kuliah Deep Learning STEI ITB
Setia Juli Irzal Ismail
 
slide-share.pdf
slide-share.pdfslide-share.pdf
slide-share.pdf
Setia Juli Irzal Ismail
 
slide-lp3i-final.pdf
slide-lp3i-final.pdfslide-lp3i-final.pdf
slide-lp3i-final.pdf
Setia Juli Irzal Ismail
 
society50-jul-share.pdf
society50-jul-share.pdfsociety50-jul-share.pdf
society50-jul-share.pdf
Setia Juli Irzal Ismail
 
57 slide presentation
57 slide presentation57 slide presentation
57 slide presentation
Setia Juli Irzal Ismail
 
Panduan Proyek Akhir D3 Teknologi Komputer Telkom University
Panduan Proyek Akhir D3 Teknologi Komputer Telkom UniversityPanduan Proyek Akhir D3 Teknologi Komputer Telkom University
Panduan Proyek Akhir D3 Teknologi Komputer Telkom University
Setia Juli Irzal Ismail
 
Sosialisasi kurikulum2020
Sosialisasi kurikulum2020Sosialisasi kurikulum2020
Sosialisasi kurikulum2020
Setia Juli Irzal Ismail
 
Welcoming maba 2020
Welcoming maba 2020Welcoming maba 2020
Welcoming maba 2020
Setia Juli Irzal Ismail
 
Slide jul apcert agm 2016
Slide jul apcert agm 2016Slide jul apcert agm 2016
Slide jul apcert agm 2016
Setia Juli Irzal Ismail
 
Tugas besar MK Keamanan Jaringan
Tugas besar MK Keamanan Jaringan Tugas besar MK Keamanan Jaringan
Tugas besar MK Keamanan Jaringan
Setia Juli Irzal Ismail
 
05 wireless
05 wireless05 wireless
05 wireless
Setia Juli Irzal Ismail
 
04 sniffing
04 sniffing04 sniffing
04 sniffing
Setia Juli Irzal Ismail
 
03 keamanan password
03 keamanan password03 keamanan password
03 keamanan password
Setia Juli Irzal Ismail
 
02 teknik penyerangan
02 teknik penyerangan02 teknik penyerangan
02 teknik penyerangan
Setia Juli Irzal Ismail
 
01a pengenalan keamanan jaringan upload
01a pengenalan keamanan jaringan upload01a pengenalan keamanan jaringan upload
01a pengenalan keamanan jaringan upload
Setia Juli Irzal Ismail
 
Kajian3 upload
Kajian3 uploadKajian3 upload
Kajian3 upload
Setia Juli Irzal Ismail
 
1.pendahuluan sistem operasi
1.pendahuluan sistem operasi1.pendahuluan sistem operasi
1.pendahuluan sistem operasi
Setia Juli Irzal Ismail
 
Minggu 2-2 Praktikum Instalasi RouterOS pada Virtualisasi-2.pdf
Minggu 2-2  Praktikum Instalasi RouterOS pada Virtualisasi-2.pdfMinggu 2-2  Praktikum Instalasi RouterOS pada Virtualisasi-2.pdf
Minggu 2-2 Praktikum Instalasi RouterOS pada Virtualisasi-2.pdf
Setia Juli Irzal Ismail
 
Introduction to self-Supervised learning - kuliah machine learning STEI ITB
Introduction to self-Supervised learning - kuliah machine learning STEI ITBIntroduction to self-Supervised learning - kuliah machine learning STEI ITB
Introduction to self-Supervised learning - kuliah machine learning STEI ITB
Setia Juli Irzal Ismail
 
Materi lanjutan Deep Learning S1 Telekomunikasi - STEI ITB
Materi lanjutan Deep Learning  S1 Telekomunikasi - STEI ITBMateri lanjutan Deep Learning  S1 Telekomunikasi - STEI ITB
Materi lanjutan Deep Learning S1 Telekomunikasi - STEI ITB
Setia Juli Irzal Ismail
 
Slide materi pengantar kuliah Deep Learning STEI ITB
Slide materi pengantar kuliah Deep Learning STEI ITBSlide materi pengantar kuliah Deep Learning STEI ITB
Slide materi pengantar kuliah Deep Learning STEI ITB
Setia Juli Irzal Ismail
 
Panduan Proyek Akhir D3 Teknologi Komputer Telkom University
Panduan Proyek Akhir D3 Teknologi Komputer Telkom UniversityPanduan Proyek Akhir D3 Teknologi Komputer Telkom University
Panduan Proyek Akhir D3 Teknologi Komputer Telkom University
Setia Juli Irzal Ismail
 

Recently uploaded (20)

Political History of Pala dynasty Pala Rulers NEP.pptx
Political History of Pala dynasty Pala Rulers NEP.pptxPolitical History of Pala dynasty Pala Rulers NEP.pptx
Political History of Pala dynasty Pala Rulers NEP.pptx
Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACYUNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
DR.PRISCILLA MARY J
 
Metamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative JourneyMetamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative Journey
Arshad Shaikh
 
How to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 WebsiteHow to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 Website
Celine George
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
Unit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdfUnit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdf
KanchanPatil34
 
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Celine George
 
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 AccountingHow to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
Celine George
 
Quality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdfQuality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdf
Dr. Bindiya Chauhan
 
Handling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptxHandling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptx
AuthorAIDNationalRes
 
Sinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_NameSinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_Name
keshanf79
 
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 
To study the nervous system of insect.pptx
To study the nervous system of insect.pptxTo study the nervous system of insect.pptx
To study the nervous system of insect.pptx
Arshad Shaikh
 
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Library Association of Ireland
 
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
Celine George
 
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Library Association of Ireland
 
Operations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdfOperations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdf
Arab Academy for Science, Technology and Maritime Transport
 
One Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learningOne Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learning
momer9505
 
To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACYUNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
DR.PRISCILLA MARY J
 
Metamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative JourneyMetamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative Journey
Arshad Shaikh
 
How to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 WebsiteHow to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 Website
Celine George
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
Unit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdfUnit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdf
KanchanPatil34
 
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Celine George
 
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 AccountingHow to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
Celine George
 
Quality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdfQuality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdf
Dr. Bindiya Chauhan
 
Handling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptxHandling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptx
AuthorAIDNationalRes
 
Sinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_NameSinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_Name
keshanf79
 
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 
To study the nervous system of insect.pptx
To study the nervous system of insect.pptxTo study the nervous system of insect.pptx
To study the nervous system of insect.pptx
Arshad Shaikh
 
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Library Association of Ireland
 
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
Celine George
 
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Library Association of Ireland
 
One Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learningOne Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learning
momer9505
 
To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 

03 tk2123 - pemrograman shell-2

  • 1. TK2123 Pemrograman Shell Semester Genap 2015/2016 TASS, Bandung 2016 www.tass.telkomuniversity.a c.id Hanya dipergunakan untuk kepentingan pengajaran di lingkungan Telkom Applied Science School (TASS) Dasar Pemrograman Shell
  • 2. Kondisi / Pencabangan Perulangan Berhenti / keluar blok kendali Struktur Kendali
  • 3. Alternatif proses yang akan dieksekusi berdasar nilai kebenaran kondisi. Operai logika : AND, OR, NOT Kondisi
  • 4. if [ expression 1 ] then Statement(s) to be executed if expression 1 is true elif [ expression 2 ] then Statement(s) to be executed if expression 2 is true elif [ expression 3 ] then Statement(s) to be executed if expression 3 is true else Statement(s) to be executed if no expression is true fi Sintaks
  • 5. #!/bin/bash if [ "$#" -gt 0 ] then echo "There's Beans" fi if [ "$1" = "cool" ] then echo "Cool Beans" fi nano latihan3a.sh
  • 6. #!/bin/bash if [ "$1" = "cool" ] then echo "Cool Beans" else echo "Not Cool Beans" fi nano latihan3b.sh
  • 7. #!/bin/bash if [ "$1" = "cool" ] then echo "Cool Beans" elif [ "$1" = "neat" ] then echo "Neat cool" else echo "Not Cool Beans“ fi nano latihan3c.sh
  • 8. #!/bin/bash if [ "$1" = "cool" ] then echo "Cool Beans" else echo "Not Cool Beans" fi nano latihan3d.sh
  • 9. #!/bin/bash if [ -f "$1" ] then echo "$1 is a file" else echo "$1 is not a file" fi nano latihan3e.sh
  • 11. #!/bin/bash a=10 b=20 if [ $a == $b ] then echo "a is equal to b" elif [ $a -gt $b ] then echo "a is greater than b" elif [ $a -lt $b ] then echo "a is less than b" else echo "None of the condition met" fi nano latihan3f.sh
  • 12. $ true $ echo $? #Hasilnya ? $ false $ echo $? #Hasilnya ? True and or False $ if true; then echo "It's true."; fi #Hasilnya ? $ if false; then echo "It's false."; fi #Hasilnya ?
  • 13. Banyak dipakai dengan perintah if untuk membuat keputusan benar/salah. Jika ekspresi bernilai benar, test keluar dengan status 0, sebaliknya berstatus 1 Bentuk sintaksnya : # Pertama test expression # Kedua [ expression ] Test
  • 15. #!/bin/bash if [ -f .bash_profile ];then echo "You have a .bash_profile" else echo "You have no .bash_profile!" fi nano latihan3g.sh
  • 16. #!/bin/bash if test $1 -gt 0 then echo "$1 number is positive" fi nano latihan3h.sh
  • 17. Merupakan perintah yang dipakai untuk mengakhiri skrip dan menset status exitnya. Contoh #Keluar skrip dengan exit status 0 (success) exit 0 #Keluar skrip dengan exit status 1 (failure) exit 1 Exit
  • 18. $ id -u 501 $ su Password: # id -u 0 ID super user
  • 19. #!/bin/bash if [ $(id -u) = "0" ]; then echo "superuser" fi nano latihan3i.sh
  • 20. #!/bin/bash if [ $(id -u) != "0" ]; then echo “Harus superuser untuk menjalankan skrip ini" exit 1 fi nano latihan3j.sh
  • 21. #!/bin/bash if [ $# -eq 0 ] then echo "$0 : Ketikkkan angka integer" exit 1 fi if test $1 -gt 0 then echo "$1 bilangan positif" else echo "$1 bilangan negatif" fi nano latihan3k.sh
  • 22. Case – 1 (multiple if dengan variabel tunggal) case $variable in match_1) commands_to_execute_for_1 ;; match_2) commands_to_execute_for_2 ;; match_3) commands_to_execute_for_3 ;; . . . *) (Optional - any other value) commands_to_execute_for_no_match ;; esac
  • 24. #!/bin/bash case $( arch ) in # "arch" arsitektur mesin # Equivalent to 'uname -m' ... i386 ) echo "80386-based machine";; i486 ) echo "80486-based machine";; i586 ) echo "Pentium-based machine";; i686 ) echo "Pentium2+-based machine";; * ) echo "Other type of machine";; esac nano latihan3l.sh
  • 25. #!/bin/bash option="${1}" case ${option} in -f) FILE="${2}" echo "File name is $FILE" ;; -d) DIR="${2}" echo "Dir name is $DIR" ;; *) echo "`basename ${0}`:usage: [-f file] | [-d directory]" exit 1 # Command to come out of the program with status 1 ;; esac nano latihan3m.sh
  • 26. #!/bin/bash NOW=$(date +"%a") case $NOW in Mon) echo "Full backup";; Tue|Wed|Thu|Fri) echo "Partial backup";; Sat|Sun) echo "No backup";; *) ;; esac nano latihan3n.sh
  • 27. #!/bin/bash # Skrip backup mysql, webserver & file-file ke tape opt=$1 case $opt in sql) echo "Running mysql backup using mysqldump tool..." ;; sync) echo "Running backup using rsync tool..." ;; tar) echo "Running tape backup using tar tool..." ;; *) echo "Backup shell script utility" echo "Usage: $0 {sql|sync|tar}" echo "sql : Run mySQL backup utility." echo "sync : Run web server backup utility." echo "tar : Run tape backup utility." ;; esac nano latihan3o.sh
  • 28. #!/bin/bash echo -n "Do you agree with this? [yes or no]: " read yno case $yno in [yY] | [yY][Ee][Ss] ) echo "Agreed" ;; [nN] | [n|N][O|o] ) echo "Not agreed, can't proceed the installation"; exit 1 ;; *) echo "Invalid input" ;; esac nano latihan3p.sh
  • 29. #!/bin/bash case "$1" in 'start') echo "Starting application" /usr/bin/startpc ;; 'stop') echo "Stopping application" /usr/bin/stoppc ;; 'restart') echo "Usage: $0 [start|stop]" ;; esac nano latihan3q.sh
  • 30. !/bin/bash # Testing ranges of characters. echo; echo "Hit a key, then hit return." read Keypress case "$Keypress" in [[:lower:]] ) echo "Lowercase letter";; [[:upper:]] ) echo "Uppercase letter";; [0-9] ) echo "Digit";; * ) echo "Punctuation, whitespace, or other";; esac # range karakter [square brackets], # range POSIX [[double square brackets]] nano latihan3r.sh
  • 31. Merupakan struktur kendali yang memungkinkan perulangan tertentu terhadap proses. Yang harus diperhatikan : Kondisi berhenti harus tercapai  jika tidak maka akan terjadi ENDLESS LOOP (hang) Perulangan (LOOPING)
  • 32. while [ condition ] do command1 command2 commandN done Macam perulangan - 1
  • 33. for { variable name } in { list } do command1 command2 … commandN done Macam perulangan - 2
  • 34. for (( expr1; expr2; expr3 )) do command1 command2 … commandN done
  • 35. until [ condition ] do command1 command2 commandN done Macam perulangan - 3
  • 36. #!/bin/bash c=1 while [ $c -le 5 ] do echo "Welcome $c times" (( c++ )) done nano latihan3s.sh
  • 37. #!/bin/bash for i in 1 2 3 4 5 do echo "Welcome $i times" done nano latihan3t.sh
  • 38. #!/bin/bash for ((  i = 0 ;  i <= 5;  i+ +  )) do   echo "Welcome $i times" done nano latihan3u.sh
  • 39. #!/bin/bash i=1; for (( ; ; )) do sleep $i echo "Number: $((i++))" done nano latihan3v.sh
  • 40. #!/bin/bash i=1 for day in Mon Tue Wed Thu Fri do echo "Weekday $((i++)) : $day" done nano latihan3w.sh
  • 41. #!/bin/bash i=1 for day in "Mon Tue Wed Thu Fri" do echo "Weekday $((i++)) : $day" done nano latihan3x.sh
  • 42. #!/bin/bash i=1 weekdays="Mon Tue Wed Thu Fri" for day in $weekdays do echo "Weekday $((i++)) : $day" done nano latihan3y.sh
  • 43. #!/bin/bash for (( i=1; i <= 5; i++ )) do echo "Random number $i: $RANDOM" done nano latihan3z0.sh
  • 44. #!/bin/bash for ((i=1, j=10; i <= 5 ; i+ +, j=j+5)) do echo "Number $i: $j" done nano latihan3z1.sh
  • 45. #!/bin/bash pilih= until [ "$pilih" = "0" ]; do echo "" echo "PROGRAM MENU" echo "1 - display free disk space" echo "2 - display free memory" echo "" echo "0 - exit program" echo "" echo -n "Enter selection: " read pilih echo "" case $pilih in 1 ) df ;; 2 ) free ;; 0 ) echo “Tekan satu key. . ." ; read -n 1; exit ;; * ) echo “Ketikkan 1, 2, atau 0" esac done nano latihan3z2.sh
  • 46. echo -e : enable interpretation of backslash escapes tput : menggerakkan kursor di layar Warna dan kursor
  • 47. Warna
  • 48. #!/bin/bash for x in 0 1 4 5 7 8 ; do for i in `seq 30 37`; do for a in `seq 40 47`; do echo -ne "e[$x;$i;$a""me[$x;$i;$a""me[0;37;40m" done echo; done done echo " "; nano tabwarna.sh
  • 49. $ PS1="[033[0;32;40mu@h:w$ ]” $ PS1="[033[0;37;44mu@033[0;32;43mh:033[0;33;41mw$033[0m]“ $ PS1=" [033[1;34;40m[033[1;31;40mu@h:w033[1;34;40m]033[1;37;40m $033[0;37;0m] " Latihan
  • 50. #!/bin/bash for (( i = 1; i <= 9; i++ ))  do     for (( j = 1 ; j <= 9; j++ ))     do         tot=`expr $i + $j`         tmp=`expr $tot % 2`          if [ $tmp -eq 0 ]; then              echo -e -n "033[47m “ #putih          else              echo -e -n "033[40m “ #Hitam         fi    done   echo -e -n "033[40m" #black  echo "" done nano latihan3z3.sh
  • 51. - Memindahkan posisi kursor ke baris L kolom C : 033[<L>;<C>H atau 033[<L>;<C>f - Memindahkan kursor ke atas N baris : 033[<N>A - Memindahkan kursor ke bawah N baris : 033[<N>B - Memindahkan kursor maju N kolom : 033[<N>C - Memindahkan kursor mundur N kolom : 033[<N>D - Hapus layar, kursor ke (0,0) #sudut kiri atas 033[2J - Hapus sampai akhir baris : 033[K - Simpan posisi kursor : 033[s - Restore posisi kursor : 033[u Kursor
  • 52. $ tput cup 2 3 $ tput clear $ tput cols $ tput lines $ tput -S <<END >clear > cup 2 4 > END $ tput setb 4 $ tput setf 4 $ tput bold $ tput sgr0 $ echo `tput bold`guide`tput sgr0` $ tput smul $ tput rmul $ echo `tput smul`guide`tput rmul` $ tput civis $ tput cnorm Latihan
  • 53. #!/bin/bash clear for (( i=1; i <= 5; i++ ));do for (( j=1; j <= 100; j++ ));do acakx=$(( RANDOM%20+5 )) acaky=$(( RANDOM%70+10 )) acakw=$(( RANDOM%8+1 )) tput cup $acakx $acaky echo -en "033[1;3${acakw};4${acakw}m*" sleep 0.05 done done echo -en "033[0m" nano blinkindark.sh
  • 54. #!/bin/bash for a in 0 1 4 5 7; do echo "a=$a " for (( f=0; f<=9; f++ )) ; do for (( b=0; b <=9; b++ )) ; do echo -ne "033[${a};3${f};4${b}m" echo -ne "033[${a};3${f};4${b}m" echo -ne "033[0m " done echo done echo done echo nano tabelwarna.sh
  • 55. #!/bin/bash clear for ((i=1;i<= 8; i++)) do for ((j=1;j<= 8; j++)) do total=$(($i+$j)) tmp=$(($total%2)) if [ $tmp -eq 0 ] then echo -e -n "033[47m $j " #ke samping else echo -e -n "033[40m $j " #ke samping sleep 0.1 fi done echo "" #ke bawah done echo -e -n "033[0m" nano chessboard.sh
  • 56. #!/bin/bash tput clear tput cup 3 15 tput setaf 3 echo "XYX Appl. V.1" tput sgr0 tput cup 5 17 # Set reverse video mode tput rev echo "M A I N - M E N U" tput sgr0 tput cup 7 15 echo "1. User Management" tput cup 8 15 echo "2. Service Management" tput cup 9 15 echo "3. Process Management" tput cup 10 15 echo "4. Backup" tput bold tput cup 12 15 read -p "Enter your choice [1-4] " choice tput clear tput sgr0 tput rc nano menutput.sh
  • 57. #!/bin/bash echo -en "033[0m" clear warna=( 41 43 45 44 46 47 42 ) for (( i=0; i <= 6; i++ )) do tput cup 10 0 for (( j=1; j <= 20;j++ )) #ke kanan do echo -en "033[${warna[i]}m " sleep 0.03 done for (( j=10; j <= 20; j++ )) #ke bawah do tput cup $j 20 echo -en "033[s" echo -e "033[${warna[i]}m " done for (( j=20; j >= 1; j-- )) #ke kiri do tput cup 20 $j echo -en "033[s" echo -en "033[${warna[i]}m " sleep 0.03 done for (( j=20; j >= 12; j-- )) #ke atas do tput cup $j 0 echo -en "033[s" echo -en "033[${warna[i]}m " sleep 0.03 done done echo -en "033[0m" nano onyamuk.sh