【问题标题】:Function runs on CLI but not from bash script函数在 CLI 上运行,但不是从 bash 脚本运行
【发布时间】:2013-09-01 09:06:42
【问题描述】:

我制作了一个 bash 脚本来生成一个我一直使用的 ssh,并带有几个选项。最后,它会为要执行的任何内容回显一个字符串,然后执行它。目前我正在尝试添加功能以添加 bash 命令以在 ssh 完成后运行,但它会给出如下错误:

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"

【问题讨论】:

  • 产生错误的确切命令是什么?或者至少向我们展示生成和调用命令的脚本部分。

标签: bash unix ssh executable


【解决方案1】:

这很可能是由于引用过强造成的。这个错误行

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

表明 bash 不会尝试执行带有参数 'hello' 后跟命令 bash -l 的命令 /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,但除非我看到你提供的更多代码,否则我无法确定。

【讨论】:

    猜你喜欢
    • 2016-02-03
    • 2016-04-09
    • 1970-01-01
    • 2013-03-07
    • 1970-01-01
    • 2010-09-14
    • 1970-01-01
    • 2017-07-19
    • 1970-01-01
    相关资源
    最近更新 更多