1. Judgment statement
#!/bin/bash
read -p "please input (Y/N)" ynif [ "$yn" == "Y" ] || [ "$yn" == "y" ]; then
echo "ok,continue!"
exit 0
fi
if [ "$yn" == "N" ] || [ "$yn" == "n" ]; then
echo "no,interrupt!"
exit 0
fi
echo "sorry,i dont know what is your choice" && exit 0
2、case ...esac
for example:
#!/bin/bash
case $1 in
"hello")
echo "hello,how are you!"
;;
"")
echo "you must input someword"
;;
*)
echo "Usage $0 {hello}"
;;
esac
3、function fname() {
block
}
4. Cycle
while [ condition ]
do
program paragraph
done
example
while [ "$yn" != "YES" ] && [ "$yn" != 'yes' ]
do
read -p "please input yes/YES to stop the program" yn
done
Similarly
until [ condition ]
do
program paragraph
done
5. Already know how many times to loop
for ((initial value; limit value; execution step))
do
block
done
6. Script tracking and debugging
sh [-nvx] scripts.sh
Parameter -n: do not execute the script, only query the syntax
-v: output the script to the screen before executing the script
-x: display the used script to the screen