学习shell编程,简单的写了一个shell脚本。
这里有一个简单的shell教程:
- #!/bin/bash
- # this is shell script test file ,just for study
- #1. if and test
- if test -f shell.sh
- then
- echo -e "\n Hello shell \n"
- else
- echo -e "\n No shell.sh file \n"
- fi
- #another test
- if [ -f shell.sh ]
- then
- echo -e "\n Hello shell \n"
- else
- echo -e "\n No shell.sh file \n"
- fi
- #2. for loop and echo
- for var in 1 2 3 "bash shell "
- do
- echo -n $var
- done
- echo -e
- for var in 1 2 3 "bash shell" # -n -e diff
- do
- echo -e $var
- done
- for var in 1 2 3 "bash shell" # -n -e diff
- do
- printf $var
- done
- echo -e
- #3. while
- while [ "$0 != "untuntu" " ]
- do
- echo -e "while loop"
- break
- done
- #4. input
- echo -n "Please input usename :"
- read usename
- echo -n "Please input password :"
- read password
- case $password in
- y|yes|Y|YES) echo -e "$usename login";;
- n|no|N|NO) echo -e "password error";;
- *) echo -e " "
- esac
- #5. math and compare
- #-eq 等于 -ne 不等于 -gt 大于
- #-lt 小于 -le 小于等于 -ge 大于等于
- sum=0
- i=0
- while [ $i -le 100 ]
- do
- let sum=$sum+$i
- let i=i+1
- done
- echo -e "sum=$sum"
阅读(1692) | 评论(0) | 转发(0) |