shell选择和循环语句

调用脚本$();

if语句:

if[ -d ];then

xxx

else

xxx

fi

case语句:

case xxx in

xx)

xxx

;;

esac

while语句

while((xx))

do 

xxx

done

 

demo:

#!/bin/bash
a=$(uname -r)
echo $a
function test_if
{
if [ -d /root ];then
result="\"ok\""
printf "ok\n"
else
printf "error\n"
result=error
fi
}

function test_if_ret
{
printf "%s\n" $1
printf "%d\n" 0xff
}

function test_case
{
case $1 in
"ok")
printf "ok in case\n"
;;
"error")
printf "error in case \n"
;;
esac
}
function test_for
{
i=0
while((i<25))
do
echo i=$((i++))
done

}
test_if
ret_if="data"
ret_if=$(test_if_ret $result)
echo $result

posted @ 2019-03-05 11:03  断网用户  阅读(324)  评论(0编辑  收藏  举报