当命令是 if
语句的一部分时,我该如何在 shell 中将命令拆分成多行?
这样做有效:
if ! fab --fabfile=.deploy/fabfile.py --forward-agent --disable-known-hosts deploy:$target; then rc=1
fi
这不起作用:# does not work:
if ! fab --fabfile=.deploy/fabfile.py \
--forward-agent \
--disable-known-hosts deploy:$target; then
rc=1
fi
我得到的不是整个命令执行的结果,而是:
./script.sh: line 73: --forward-agent: command not found
更重要的是,我对Bash的理解中缺少什么,可以帮助我在未来理解这些问题及类似问题?
$ if ! cp -n log/server1.log \ .; then echo no copy; fi
,没有错误,并在\
后换行。 - Miserable Variable\
后面有空格吗?它们很难看到。如果有的话,你可能想要查看你的编辑器是否可以去除末尾空格或使其更加可见。 - msw