在OS X 10.9.5中
我写了一个Shell脚本(通过vim)。保存它并导航到此脚本,然后
它运行完美(在iTerm和sh code.sh终端)。
同一目录中的相同命令通过Mac Automator总是产生错误。为什么?
在Automator和Terminal中。
echo $SHELL /bin/bash为什么不能通过自动化程序运行外壳脚本。

发布于 2016-07-11 22:27:20
这个问题可以通过在当前代码上添加以下代码来解决:
export PATH=/usr/local/bin:$PATH发布于 2014-08-06 21:15:06
我怀疑是cd Desktop的问题。您可以尝试:
(cd ~/Desktop; sh code.sh)但是:
code.sh成为可执行的,这样你就不需要用sh来调用它了。这是使用chmod 0755 code.sh.~/Desktop/code.sh即可调用:#!/bin/bash dir=$(dirname $0) cd $dir # do work
例如:
➜ ~ cat tmp/code.sh
#!/bin/bash
dir=$(dirname $0)
cd $dir
ls -l
➜ ~ chmod 0755 tmp/code.sh
➜ ~ tmp/code.sh
total 64
drwxr-xr-x 6 andy staff 204 Feb 22 18:53 Archives
drwxr-xr-x 11 andy staff 374 Jun 18 13:59 DerivedData
-rw-r--r-- 1 andy staff 225 May 20 13:44 MyFirstProgram.X
-rwxr-xr-x 1 andy staff 3072 May 20 13:44 MyFirstProgram.exe
drwxr-xr-x 3 andy staff 102 Jan 6 2014 bug_reports
-rwxr-xr-x 1 andy staff 43 Aug 6 14:15 code.sh
-rw-r--r-- 1 andy staff 11539 May 20 08:33 iOS_Team_Provisioning_Profile_.mobileprovision
-rw-r--r-- 1 andy staff 1438 May 20 08:40 ios_development.cer
-rwxr-xr-x 1 andy staff 272 Aug 5 08:55 script.sh发布于 2014-09-03 17:28:28
解决方案
创建两个输出文件: In Automator:env > ~/Desktop/file_1.txt in iTerm:env > ~/Desktop/file_2.txt
比较
diff -y ~/Desktop/file_1.txt ~/Desktop/file_2.txt
而且,瞧,这里有一些有趣的区别!在脚本中插入不同之处,例如export LANG=de_DE.UTF-8,它就可以工作了!
https://stackoverflow.com/questions/25161100
复制相似问题