我一直试图弄清楚这有什么不对,但是无法弄清楚..
这部分似乎是一个错误..
elif [ $operation = "man" ]; then
if [ $aug1 = "add" ]; then # <- Line 75
echo "Man Page for: add"
echo ""
echo "Syntax: add [number 1] [number 2]"
echo ""
echo "Description:"
echo "Add two different numbers together."
echo ""
echo "Info:"
echo "Added in v1.0"
echo ""
elif [ -z $aug1 ]; then
echo "Please specify a command to read the man page."
else
echo "There is no manual page for that command." …Run Code Online (Sandbox Code Playgroud) 我喜欢在shell脚本中的函数之间使用类似生成器的模式.像这样的东西:
parse_commands /da/cmd/file | process_commands
Run Code Online (Sandbox Code Playgroud)
但是,这种模式的基本问题是,如果parse_command遇到错误,我发现通知process_command失败的唯一方法是通过显式告知它(例如echo"FILE_NOT_FOUND").这意味着必须对parse_command中的每个可能的错误操作进行隔离.
难道没有办法使用非零退出代码检测左侧是否退出?
我正在尝试自动化我们的应用程序备份.过程的一部分是检查的退出状态egrep中的if语句:
if [ ! -f /opt/apps/SiteScope_backup/sitescope_configuration.zip ] ||
[ egrep -i -q "error|warning|fatal|missing|critical" "$File" ]
then
echo "testing"
fi
Run Code Online (Sandbox Code Playgroud)
我希望它输出,testing因为文件存在并egrep返回成功,但我得到一个错误:
-bash: [: too many arguments
Run Code Online (Sandbox Code Playgroud)
我尝试了各种语法 - 附加括号,引号等但错误仍然存在.
请帮助我理解我哪里出错了.