1.shell
echo $HOME
默认在shell中编写的变量全部是局部变量,如果重新打开console的话,那么这些变量将全部丢失,全局的变量可以写在文件~/.bashrc文件。
2.判断
!/bin/sh #if-elif-else-fi user_input_fruit = ""; echo -e "please input a kind of fruit: "; read user_input_fruit; if [ $user_input_fruit = "apple" ] then echo -e "You input e[1;32mAPPLEe[0m! "; elif [ $user_input_fruit = "grape" ] then echo -e "You input e[1;34mGRAPEe[0m! "; else echo -e "Please input a kind of e[1;36mFRUITe[0m! "; fi
3.循环
!/bin/sh #for-do-done user_input_number=1; echo "please input a number:"; read user_input_number; i=0; for (( $i=0; $i<$user_input_number; $i++)) do echo $i," "; done
!/bin/sh #while loop n=10; i=0; while [ $i -le $n ] do echo $i." "; done
!/bin/sh #case-in-;;-esac user_input_genda="male"; echo "tell me your genda: "; read user_input_gendar; case $user_input_gender in "male") echo "Wo, good man ";; "female") echo "Ohh,smart girl ";; *) echo "You must be jokking ";; esac