shell for 学习

前端之家收集整理的这篇文章主要介绍了shell for 学习前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
#!/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
原文链接:https://www.f2er.com/bash/388303.html

猜你在找的Bash相关文章