意外的EOF,同时寻找匹配的“&” [英] unexpected EOF while looking for matching `"'
本文介绍了意外的EOF,同时寻找匹配的“&”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我从命令行执行时,命令工作正常。但是当我从shell脚本执行它时会抛出一个错误
The command works fine when I execute from command line. However It throws an error when I execute it from shell script
rsync -avz -e ssh --exclude-from=rsync.file --rsync-path="sudo rsync" ostnfe/ ubuntu@mask.compute-1.amazonaws.com:/var/www/ostnfe
来自shell脚本的代码:
Code from shell script:
CMD='rsync -avz -e ssh --exclude-from=rsync.file --rsync-path="sudo rsync" '$1'/ ubuntu@'$AMZ':/var/www/'$2
$CMD
错误:
bash: -c: line 0: unexpected EOF while looking for matching `"'
bash: -c: line 1: syntax error: unexpected end of file
推荐答案
您只需使用shell函数:
You could just use a shell function instead:
cmd () {
rsync -avz -e ssh --exclude-from=rsync.file --rsync-path="sudo rsync" $1/ ubuntu@$AMZ:/var/www/$2
}
# calling with args
cmd "$1" "$2"
# alternatively, calling through variable without args
VAR='eval cmd "$1" "$2"'
$VAR
更新:编辑cmd()以表示工作解决方案。
Update: Edited cmd() to represent the working solution.
这篇关于意外的EOF,同时寻找匹配的“&”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文