码迷,mamicode.com
首页 > 系统相关 > 详细

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

时间:2021-04-13 12:16:49      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:roo   bin   echo $?   shell命令   命令   exe   exec   exiting   this   


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

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

标签:roo   bin   echo $?   shell命令   命令   exe   exec   exiting   this   

原文地址:https://www.cnblogs.com/zhudaheng123/p/14649471.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!