#!/bin/bash
echo "**********argument**********"
Echo Script Name: $
Echo First argument $
echo second argument
echo num of argument $#
echo all argument [email protected]
#function
Equal ()
{
Case $ in
$)
return 0
;;
*)
Return 1
;;
Esac
}
#if
echo "**********test if**********"
if equal $;
Then
echo "Equal"
Else
echo "Not Equal"
Fi
If [$#-gt 0];
Then
echo number of argument greater than 0
echo [email protected]
Else
echo number of argument is 0
Fi
#for
echo "**********test for**********"
For i in [email protected]
Do
Echo $i
Done
Limit=5
for ((a=1; a<= $LIMIT; a++))
Do
echo "$a"
Done
#while
echo "**********test while**********"
A=0
limit=10
While [$a-lt $LIMIT]
Do
Echo $a
a=$ ((a+1))
Done
#case
echo "**********test case**********"
Read-p "Press some key, then press RETURN:" Key
Case $KEY in
[A-za-z])
echo "It ' s a letter!"
;;
[0-9])
echo "It ' s a number!"
;;
*)
echo "Other key!"
;;
Esac
#printf
echo "**********test printf**********"
X=ABC; printf "X is now:%s, Enter new value:" $x; Read X
Run./test.sh 1 1 results are as follows:
Shell Common syntax