2013-09-01 102 views
0

我做了一个bash脚本来生成一个ssh,我总是使用一些选项。最后,它为任何要执行的内容回应一个字符串,然后执行它。目前,我想要添加的功能,在bash命令添加到运行一次ssh的完成,但它给了一个错误,像这样:功能在CLI上运行,但不是来自bash脚本

bash: /bin/echo 'hello'; bash -l: No such file or directory 

然而,如果我把它复制运行命令,并运行它从可执行文件外部,它运行完美。是否有任何理由我会从可执行文件中获取此错误,而不是从CLI获取?

它产生的一个例子命令是:

pair -c "/bin/echo 'hello'" 
Running: ssh ****@#.#.#.# -p443 -t "/bin/echo 'hello'; bash -l" 
+0

创建错误的确切命令是什么?或者至少向我们展示生成并调用命令的脚本部分。 – konsolebox

回答

0

这是因为过强的报价最有可能引起的。此错误路线

bash: /bin/echo 'hello'; bash -l: No such file or directory 

显示的bash不会尝试与随后命令bash -l参数'hello'执行命令/bin/echo。相反,bash正试图执行命令/bin/echo 'hello'; bash -l

比较:

$ ssh localhost -t "/bin/echo 'foo'; bash -l" 
foo 
$ logout # this is the new shell 
Connection to localhost closed. 

和:

$ ssh localhost -t '"/bin/echo 'foo'; bash -l"' 
bash: /bin/echo foo; bash -l: No such file or directory 
Connection to localhost closed. 

解决这个问题通常涉及eval,但我不能肯定地告诉我,除非看到你更多的代码。

相关问题