shell脚本
检测是否为root用户 # if test $UID -ne 0 ; then if [ $UID -ne 0 ];then echo "Non root user.Please run as root." else echo "Root user" fi 计算命令花费时间 start=$(date +%s) commands; statements; end=$(date +%s) difference=$(( end - start )) echo "Time taken to execute is $difference seconds." time CommandOrScriptName 更好的方式 判断命令是否成功运行 eval $@ if [ $? -eq 0 ] ; then echo "$CMD excuted successfully" else echo "$CMD excuted unsuccessfully" fi # [ $? -eq 0 ] && ... 来源: https://www.cnblogs.com/kylingx/p/11643423.html