从Mac Automator运行Shellscript

Tel*_*S X 7 macos bash automator

在OS X 10.9.5中

我写了一个Shell脚本(通过vim).保存并导航到此脚本和

sh code.sh它运行完美(在iTerm和Total Terminal中).

同一目录中的相同命令通过Mac Automator始终产生ERROR.为什么?

在Automator和终端.

echo $SHELL /bin/bash 为什么不能通过Automator运行一个shellcript. 在此输入图像描述

Luc*_*cus 5

可以通过在当前代码上方添加以下代码来解决此问题:

export PATH=/usr/local/bin:$PATH
Run Code Online (Sandbox Code Playgroud)


Dro*_*ppy 4

我怀疑是这个cd Desktop点 你可以试试:

\n\n
(cd ~/Desktop; sh code.sh)\n
Run Code Online (Sandbox Code Playgroud)\n\n

然而:

\n\n
    \n
  • 您应该使其code.sh可执行,这样您就不需要使用 来调用它sh。这是用 完成的chmod 0755 code.sh

  • \n
  • 如果您需要 shell 脚本在某个目录(即脚本所在的目录)中工作,则将其构建到脚本中,以便只需使用以下命令即可调用它~/Desktop/code.sh

    \n\n
    #!/bin/bash\ndir=$(dirname $0)\ncd $dir\n# do work\n
    Run Code Online (Sandbox Code Playgroud)
  • \n
\n\n

例如:

\n\n
\xe2\x9e\x9c  ~  cat tmp/code.sh\n#!/bin/bash\ndir=$(dirname $0)\ncd $dir\nls -l\n\n\xe2\x9e\x9c  ~  chmod 0755 tmp/code.sh\n\xe2\x9e\x9c  ~  tmp/code.sh\ntotal 64\ndrwxr-xr-x   6 andy  staff    204 Feb 22 18:53 Archives\ndrwxr-xr-x  11 andy  staff    374 Jun 18 13:59 DerivedData\n-rw-r--r--   1 andy  staff    225 May 20 13:44 MyFirstProgram.X\n-rwxr-xr-x   1 andy  staff   3072 May 20 13:44 MyFirstProgram.exe\ndrwxr-xr-x   3 andy  staff    102 Jan  6  2014 bug_reports\n-rwxr-xr-x   1 andy  staff     43 Aug  6 14:15 code.sh\n-rw-r--r--   1 andy  staff  11539 May 20 08:33 iOS_Team_Provisioning_Profile_.mobileprovision\n-rw-r--r--   1 andy  staff   1438 May 20 08:40 ios_development.cer\n-rwxr-xr-x   1 andy  staff    272 Aug  5 08:55 script.sh\n
Run Code Online (Sandbox Code Playgroud)\n