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

相关文章

用的openwrt路由器,家里宽带申请了动态公网ip,为了方便把2...
#!/bin/bashcommand1&command2&wait从Shell脚本并行...
1.先查出MAMP下面集成的PHP版本cd/Applications/MAMP/bin/ph...
1、先输入locale-a,查看一下现在已安装的语言2、若不存在如...
BashPerlTclsyntaxdiff1.进制数表示Languagebinaryoctalhexa...
正常安装了k8s后,使用kubect工具后接的命令不能直接tab补全...