shell命令学习之for
for 变量 in 值
do
声明
done
例子:for a in a b x
do
echo $a
done
输出:
a
b
x
while do 命令学习
#!/bin/sh
echo "请输入密码"
read trythis
while [ "$trythis" != "s" ]; do
echo "sorry you type word is increcct"
read trythis
done
exit 0
#!/bin/sh
echo "case测试"
read day
case "$day" in
yes|y|YES) echo "right";;
N*|n*) echo "wrong";;
esac
exit 0
&& 以及||学习
touch file_one
touch file_two
if [ -f file_one ] && echo "hello" && [ -f file_two ] && echo " there"
then
echo "in if"
else
echo "in else"
fi
exit 0
-------------------------------------------------
执行./bin.sh param
param参数需要 $1 $2来接受参数
-----函数学习
#!/bin/sh
foo(){
echo "请输入你的名字"
while true
do
echo -n "输入yes 或者 no"
read x
case "$x" in
y | yes ) return 0;;
n | no ) return 1;;
*) echo "输入错误";;
esac
done
}
echo "start exe script"
if foo "$1"
then
read name
echo "你好,$1,很好的名字"
else
echo "无所谓"
fi
exit 0