Shell代码段-base
【base】
#color config
rmsg() { echo -e "\e[1;31m$*\e[0m"; } #red
gmsg() { echo -e "\e[1;32m$*\e[0m"; } #green
bmsg() { echo -e "\033[34;49m$*\033[0m"; } #blue
#absolute path
WD="$(cd $(dirname $0); pwd)"
#root check
#方式一
ROOT_UID="0"
[ $ROOT_UID != "$UID" ] && { echo "Must be root to run this script.";exit 1; }
#方式二
user=$(whoami)
if [[ X$user != Xroot ]];then
echo -e "\E[1;31m Please execute this script under the root user! \n \E[0m"
exit 1
fi
# 脚本中生效别名
shopt -s expand_aliases
# 打印不换行
echo -n
【交互输出】
#通过echo输出重定向到输入
echo y | apt install man
#使用yes命令
yes y/n