案例1:變量、函數、判斷、比較javascript
test.shjava
- #!/bin/bash
- echo ======================== this is a bash demo========================
- printf "%s is %d years old \n" zhengjinwei 23
-
- declare count=10
- declare fruit=apple
-
- declare strNormal="we have $count ${fruit}'s "
- declare strSpecial="we have $count ${fruit} "
-
-
-
- function printStr()
- {
- if [ $count -gt 1 ] ; then
- echo "$strNormal"
- else
- echo "$strSpecial"
- fi
- }
-
- printStr
-
- echo $(uname)
-
- #########################################
- declare num=1000
- function printNum()
- {
- local num=10
-
- let num+=10
- echo $num
- }
-
- echo "the global num is : $num "
-
- echo -e "call printNum Function :"
- printNum
-
-
-
-
- o "==================this is if else fi ....test demo====================="
- if [ -f "test.sh" ] ; then
- echo "named test.sh is a file.."
- else
- echo "named test.sh is not a file.."
- fi
-
- function checkVariableHaveNum()
- {
- if [ -n "$1" ] ; then
- echo "this variable have value"
- else
- echo "this variable have not value"
- fi
- }
-
- declare g_num=10
- checkVariableHaveNum $g_num
-
- function checkVariableEqual()
- {
-
- if [ "$1" -eq "$2" ] ; then
- printf "%d == %d " $1 $2
- elif [ "$1" -ne "$2" ] ; then
- printf "%d != %d " $1 $2
- elif [ "$1" -ge "$2" ] ; then
- printf "%d >= %d " $1 $2
- elif [ "$1" -gt "$2" ] ; then
- printf "%d > %d" $1 $2
- elif [ "$1" -lt "$2" ] ; then
- printf "%d < %d" $1 $2
- else
- printf "%d <= %d" $1 $2
- fi
- }
-
- checkVariableEqual 2 4
- checkVariableEqual 4 2
- checkVariableEqual 2 2
-
案例2:字符串操做(取子串)數組