linux shell命令之非交互式Shell脚本

时间:2021-04-13 12:16:49   收藏:0   阅读:0


vi no_interaction_script1.sh
#!/bin/bash

#提示用户该脚本3秒后退出
echo "This script will quit after 3 seconds. "

#计时3s

sleep 1
echo -n "."
sleep 1
echo -n "."
sleep 1
echo "."
./no_interaction_script1.sh
This script will quit after 3 seconds.
...

vi root_or_not.sh
#!/bin/bash

#设置退出状态为5
exitcode=5

#设置退出时的提示
message="Sorry, you are not root.. exiting"

#判断当前用户是否是root

if [ $UID -ne 0 ]
then
echo "$message" >&2
exit $exitcode
fi

#如是查root用户, 将执行下面的脚本内容
echo "If the user is root, will execute this now. "
#script_end
./root_or_not.sh
Sorry, you are not root.. exiting
echo $?
5

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!