控制语句:
1.if语句
demo_if
#!/bin/bash
if [ $# -ne 1 ]
then
echo "参数多于一个"
exit 1
fi
if [ -f "$1" ]
then
filename="$1"
set $ (ls -il $filename)
inode="$1"
size="$6"
echo "Name Inode Size"
echo "$filename $inode $size"
exit 0
else
echo "$0: 不是一个普通文件"
exit 1
fi
2.for语句
#!/bin/bash
for file in $(ls d*)
do
echo $file
done
exit 0
3.while 语句
demo_while2 内容
#!/bin/bash
foo=1
while [ "$foo" -le 20 ]
do
echo "now is $foo"
foo=$(($foo+1))
done
exit 0