a standard daemon startup script:
#! /bin/shwhoami= ' WhoAmI ' pid= ' ps-u $WHOAMI | Gerp Mydaemond | awk ' {print $ ' if (test "=") Thenecho "Mydaemond [Start][stop][version]" Exit 0fiif (Test "=" status ") thenif (test "$PID" = "") Thenecho "not run" Elseecho "is Running" fiexit 0fiif (test "=" Start ") thenif (test" $PID "=" ") th En./mydaemondfiexit 0fiif (Test "=" "Stop") thenif (test "$PID" = "") Thenkill $PIDfiexit 0fiif (test "$" = "version") Thenecho "version is V1.0" Exit 0fiecho "Mydaemond [Start][stop][version]"
######################################################################################First shell script
#! /bin/sha=5b=5echo a= $aecho b= $bif (test "$a" = "$b") then echo A=belse echo A!=BFI
Example of using a ' symbol to execute a command #! /bin/shdate= ' Date ' echo "Today is" $DATE
User inputs Two numbers, calculates two numbers and #! /bin/shread Aecho ' a= ' $aread becho ' b= ' $BC = ' expr $a + $b ' echo $c
An example of a loop 5 times #! /bin/shtimes=0while ["$times"! = "5"];d o echo $times times=$[$times + 1]done
Examples of multiple branches #! /bin/shcase "$" instart) echo "is start" ;; Stop) echo "is stop" ;; *) echo "Is Nothing" Esac
Shell programming under Linux--startup script for the standard daemon