shell命令学习(一)

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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值