shell 循环 for while until ....

declare -i s
for(( i=1; i<=100; i=i+1))
do
        s=s+i
done
echo    "The count is --> $s" 

[dev@abtsvr shellTest]$ sh test8.sh
The count is --> 5050

---------------------------------

declare -i s
declare -i i
while [ "$i" != "101" ]
do
        s=s+i
        i=i+1
done
echo    "The count is --> $s"

----------------------------------------

declare -i s
declare -i i
until[ "$i" = "101" ]
do
        s=s+i
        i=i+1
done
echo    "The count is --> $s"

----------------------------------------

list="qsd qqq qddd qdsss"
for i in $list
do
        echo $i
done                             
[dev@abtsvr shellTest]$ sh test8.sh
qsd
qqq
qddd
qdsss

------------------------------------------

account='cut -d ":" -f1 /etc/passwd|sort'
echo "The following is your linux server's account"
for i in $account
do
        echo $i
done
[dev@abtsvr shellTest]$ sh test8.sh
The following is your linux server's account
cut
-d
":"
-f1
/etc/passwd|sort       、、、、、、、、、、、、、、输出有误!!!!!!!???????????

----------------------------------------------

if [ ! -e logical ]; then
        touch logical
        echo "just make a file logical"
elif [ -e logical ] && [ -f logical ]; then
        rm logical
        mkdir logical
        echo "remove file -->logical"
        echo "and make directory logical"
        exit 1
elif [ -e logical ] && [ -d logical ]; then
        rm -rf logical
        echo "remove directory -->logical"
        exit 1
else
        echo "does here have anything ?"
fi

--------------------------------

[dev@abtsvr shellTest]$ vi test11.sh


hello="hello!how are you "
echo $hello
hello! how are you
~
~
~
"test11.sh" [新] 4L, 60C 已写入                               
[dev@abtsvr shellTest]$ sh test11.sh
hello!how are you
test11.sh: line 4: hello!: command not found
[dev@abtsvr shellTest]$ sh -n test11.sh
[dev@abtsvr shellTest]$ sh -v test11.sh

hello="hello!how are you "
echo $hello
hello!how are you
hello! how are you
test11.sh: line 4: hello!: command not found
[dev@abtsvr shellTest]$ sh -x test11.sh
+ hello=hello!how are you
+ echo 'hello!how' are you
hello!how are you
+ 'hello!' how are you
test11.sh: line 4: hello!: command not found

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值