【问题标题】:osx: launching a shell script containing gnu coreutils commands, works via terminal, not via applescriptosx:启动一个包含 gnu coreutils 命令的 shell 脚本,通过终端工作,而不是通过 applescript
【发布时间】:2013-06-29 20:32:02
【问题描述】:

我已经从 osx 的 macports 安装了 gnu coreutils。此脚本[1] 使用各种 coreutils,当我从终端启动它时按预期工作,但是当我使用 applescript[2] 启动它时,我收到一条错误消息 [3]。

[1] Shell 脚本:

#!/bin/bash
path_to_open=$(gfind | grep -v "~$" | grep -v "#$" | gshuf | ghead -n 1) && open "${path_to_open}"

[2] 苹果脚本:

do shell script "sh ~/x/scripts/script1.sh"

[3] 错误信息:

error "[script_path]: line 2: gfind: command not found
[script_path]: line 2: gshuf: command not found
[script_path]: line 2: ghead: command not found" number 127

这里有什么问题?

【问题讨论】:

    标签: macos bash terminal applescript gnu-coreutils


    【解决方案1】:

    在 shell 脚本中设置 $PATH 以包含实用程序的路径:

    #!/bin/bash
    PATH=/opt/local/bin:/opt/local/sbin:$PATH
    path_to_open=$(...) && open "${path_to_open}"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-24
      • 1970-01-01
      • 2012-05-28
      • 2015-04-26
      • 2013-06-18
      • 2020-07-02
      • 1970-01-01
      相关资源
      最近更新 更多