#!/bin/bash
#iterate through all the files in a directory
for file in /home/ZHJIAB/test/*
do
if [ -d "$file" ]
then
echo "$file is a directory"
elif [ -f " $file " ]
then
echo "$file is a file "
fi
done
#!/bin/bash
# multiple variable
for (( a=1,b=10 ; a<=10 ; a++ , b-- ))
do
echo " $a - $b "
done
#!/bin/bash
#testing a multicommand while loop
var1=10
while echo $var1
[ $var1 -ge 0 ] #-ge即为大于等于
do
echo "This is inside the loop"
var1=$[ $var1 - 1 ] #shell的算数运算操作格式为$[ ]
done
#!/bin/bash
#using the util command
var1=100
until echo $var1
[ $var1 -eq 0 ]
do
echo Inside the loop: $var1
var1=$[ $var1 - 25 ]
done
#!/bin/bash
#using nestd loop
for( ( a=1 ; a<=3 ; a++ ) )
do
echo " Starting loop $a: "
for( ( b=1 ; b<=3 ; b++ ) )
do
echo " Inside loop : $b "
done
done
#!/bin/bash
#a for loop inside a while loop
var1=5
while [ $var1 -ge 0 ]
do
echo "Outer loop: $var1 "
for ( ( var2=1 ; $var2 <3 ; var2++ ) )
do
var3 = $ [ $var1 * $var2 ]
echo " Inner loop: $var1 * $var2 = $var3 "
done
var1=$[ $var1 - 1 ]
done
IFS=$'\n' //使用换行符做为字段分隔符。
IFS='\n':;" //这个赋值会将反斜杠、n、冒号、分号和双引号作为字段分隔符。
IFS=$'\n':;" //这个赋值会将换行符、冒号、分号和双引号作为字段分隔符。