//test1.sh
#!/bin/sh
if [ -d test_test ]; then
echo "It's a dir"
elif [ -f test_test ]; then
echo "It's a file"
else
echo "hehe"
fi
#!/bin/sh
if [ -d test_test ]
then
echo "test_test is dir"
elif [ -f test_test ]
then
echo "test_test id file"
else
echo "hehe"
fi
//test2.sh
#!/bin/sh
echo "Is it morning?please answer yes or no."
read YES_OR_NO
if [ $YES_OR_NO = "yes" ]
then
echo "good morning"
elif [ $YES_OR_NO = "no" ]
then
echo "good afternoon"
else
echo "sorry,$YES_OR_NO not recognized .Enter yes or no."
exit 1
fi
exit 0
//case
#!/bin/sh
echo "please input yes_or_no."
read YES_OR_NO
case "$YES_OR_NO" in
"yes")
echo "echo yes";;
"no")
echo "echo no";;
*)
echo "break"
exit 1;;
esac
exit 0;
循环
//for
#!/bin/sh
for FRUIT in apple banana pear;do
echo "I like $FRUIT"
done
#!/bin/sh
for filename in $(ls);do
if [ -d $filename ];then
echo "$filename is dir"
elif [ -f $filename ];then
echo "$filename is file"
else
echo "$file is hehe"
fi
done
//while
#!/bin/sh
echo "please input passwd"
read passwd
while [ $passwd != "passwd" ];do
echo "passwd is error"
read passwd
done
#!/bin/sh
count=1
echo "please input passwd"
read passwd
while [ $passwd != "passwd" -a $count -lt 2 ];do
echo "passwd is error"
count=$((count+1))
echo $count
read passwd
done
shell 分支循环
最新推荐文章于 2024-08-22 12:14:03 发布