学习Linux第七天
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:\r"; read user_input_fruit; if [ $user_input_fruit = "apple" ] then echo -e "You input \e[1;32mAPPLE\e[0m!\r"; elif [ $user_input_fruit = "grape" ] then echo -e "You input \e[1;34mGRAPE\e[0m!\r"; else echo -e "Please input a kind of \e[1;36mFRUIT\e[0m!\r"; 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,"\r"; 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:\r"; read user_input_gendar; case $user_input_gender in "male") echo "Wo, good man\r";; "female") echo "Ohh,smart girl\r";; *) echo "You must be jokking\r";; esac