February 22 2018 Thursday
Weather : overcast
1、需求:
写一个shell脚本,检查指定的shell脚本是否有语法错误,若有错误,首先显示错误信息,然后提示用户输入q或者Q退出脚本,输入其他内容则直接用vim打开该shell脚本。
[root@Dasoncheng sbin]# cat h.sh
#!/bin/bash
sh -n $1 &>/tmp/err
if [ $? -eq 0 ];
then
echo "The script is ok"
else
cat /tmp/err
read -p "Please input q/Q to exit , or others to edit it by vim: " n
if [ "$n" == "q" ] || [ "$n" == "Q" ];
then
exit
else
vim $1
exit
fi
fi