#!/bin/bash
#a.sh
current_date1=$(date)
current_date2=\`date\`
current_date3={\`date\`}
echo current data is [$current_date1]
echo current data is [$current_date2]
echo current data is [$current_date3]
if条件判断
#!/bin/bash
#a.sh
if [[ $1 == 1 ]]; then
echo "first argument is 1"
else
echo "first argument is not 1"
fi # 调用命令: bash a.sh 1
case分支判断
#!/bin/bash
#a.sh
case $1 in
1) echo "the case is 1" ;;
2) echo "the case is 2" ;;
3) echo "the case is 3" ;;
4) echo "the case is 4" ;;
*) echo "no case match first argument" ;;
esac # 调用命令: bash a.sh 2
for循环语句
#!/bin/bash
#a.sh
for (( i = 0; i < 10; i++ )); do
echo "current value is $i"
done
for i in 1 2 3 4 5; do
echo "current value is $i"
done
while循环
#!/bin/bash
#a.sh
i=$1
while [[ $i > 0 ]];
do
echo "now i's value is $i"
let "i=i-1"
done