您的位置:首页 > 运维架构 > Shell

shell 练习(for,while,until,local)

2015-05-28 16:49 369 查看
#!/bin/bash

for variable1 in 1 2 3 4 5
do
echo "Hello,Welcome $variable1 times"
done

for var in {1..5}
do
echo "index $var"
done

sum=0

for i in {1..100..2}
do
let "sum+=i"
done

echo "sum=$sum"

sum=0
for i in $( seq 1 2 100 )
do
let "sum+=i"
done

echo "sum=$sum"

for file in $( ls )
do
echo "file: $file"
done

echo "number of arguments is $#"

echo "What you input is:"

for argument in "$*"
do
echo "$argument"
done

for(( i=1;i <= 5;i++))
do
echo "$i"
done

echo "=====================================\n"

int=1

while(( "$int" <= 5 ))
do
echo "$int"
let "int++"
done

i=0

until [[ "$i" -gt 5 ]]
do

let "square=i*i"
echo "$i*$i=$square"
let "i++"
done


#!/bin/bash

text="global variable"

use_local_var_fun()
{
local text="local variable"
echo "In function use_local_var_fun"
echo $text
}

echo "Execute the function use_local_var_fun"
use_local_var_fun

echo "out of function use_local_var_fun"

echo "$text"

exit 0
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: