加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

shell for 学习

发布时间:2020-12-15 19:35:41 所属栏目:安全 来源:网络整理
导读:#!/bin/bash for_1 () { echo "for 1 show item" for var in item1 item2 ... itemN do echo ${var} ; done } for_2 () { echo "for 2 show 1~5" for loop in 1 2 3 4 5 do echo "The value is : ${loop} " done } for_3 () { echo "for 3 show string array
#!/bin/bash 
for_1 () {
    echo "for 1 show item"
    for var in item1 item2 ... itemN
    do
        echo ${var};
    done
}

for_2 () {
    echo "for 2 show 1~5"
    for loop in 1 2 3 4 5
    do
        echo "The value is : ${loop}"
    done
}

for_3 () {
    echo "for 3 show string array"
    for str in 'This is a string' 'This is a number'
    do
        echo ${str}   
    done
}

for_4 () {
    echo "for 4 show string"
    for str in "'This is a string' 'This is a number'"
    do
        echo ${str}   
    done
}

for_5 () {
    echo "for 5 show ls "
    for file in `ls ./`
    do
        echo ${file}
    done
}

for_6 () {
    echo "for 6 show ()"
    for ((i=1;i<=5;i++))
    do
        echo "这是第 $i 次调用";
    done

}

for_1
for_2
for_3
for_4
for_5
for_6

# for 使用命令的两种写法
for file in $(ls); do echo ${file}; done
for file in `ls`; do echo ${file};done

结果:

for 1 show item
item1
item2
...
itemN
for 2 show 1~5
The value is : 1
The value is : 2
The value is : 3
The value is : 4
The value is : 5
for 3 show string array
This is a string
This is a number
for 4 show string
'This is a string' 'This is a number'
for 5 show ls 
array.sh
for.sh
function.sh
if.sh
op.sh
params.sh
read.sh
string.sh
trap.sh
varaiable_assignment.sh
while.sh
xaa
for 6 show ()
这是第 1 次调用
这是第 2 次调用
这是第 3 次调用
这是第 4 次调用
这是第 5 次调用
array.sh
for.sh
function.sh
if.sh
op.sh
params.sh
read.sh
string.sh
trap.sh
varaiable_assignment.sh
while.sh
xaa
array.sh
for.sh
function.sh
if.sh
op.sh
params.sh
read.sh
string.sh
trap.sh
varaiable_assignment.sh
while.sh
xaa

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读