【问题标题】:How can I pass executable command as argument to adb shell?如何将可执行命令作为参数传递给 adb shell?
【发布时间】:2016-02-12 11:13:51
【问题描述】:

执行以下命令时出现错误:

$ sudo adb shell ping `cat /data/my_address.pst`

其中 my_adress.pst 文件包含 IP 地址。

但是当从 shell 执行时,同样的命令可以正常工作。

$ sudo adb shell

$ ping `cat /data/my_address.pst`

我怎样才能传递这样的可执行命令?请对此有所了解。

谢谢。

【问题讨论】:

    标签: android adb adb-shell


    【解决方案1】:

    转义 ` 使其不被 shell 解释。

    adb shell ping \`cat /data/my_address.pst\`
    

    【讨论】:

      【解决方案2】:

      您的 cat /data/my_address.pst 命令由本地 shell 执行,因此您需要转义反引号或单引号整个命令。此外,您不需要 sudo 并且使用 $() 比反引号更可取:

      adb shell 'ping $(cat /data/my_address.pst)'
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-01-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-09-09
        • 2022-12-13
        • 1970-01-01
        相关资源
        最近更新 更多