我为Mac(10.11 El Capitan)编写的所有bash命令工作得很好,但是当它们完成运行时会抛出错误。所以,例如,如果我这样做:
cat /usr/local/bin/en-deploy
你可以看到我写了这个剧本:
#Bash
#!/bin/sh
curl ec2-14-43-7-17.compute-1.amazonaws.com:10000 -d $1;
这个脚本效果很好,但是当我调用它时,我得到了:
Your branch is up-to-date with 'origin/master'.
: command not foundeploy: line 3:
第一行是预期的输出。第二行很奇怪。我需要做些什么才能摆脱它?
更新:
如果我将文件编辑为:
#!/bin/bash
curl ec2-54-173-70-97.compute-1.amazonaws.com:30000 -d $1;
我明白了:
-bash: /usr/local/bin/en-deploy: /bin/bash^M: bad interpreter: No such file or directory
答案 0 :(得分:4)
#!/bin/sh
(或Bash的#!/bin/bash
)需要是您脚本的第一行。并使用引号。
#!/bin/bash
curl 'ec2-14-43-7-17.compute-1.amazonaws.com:10000' -d "$1"
并运行dos2unix script
以确保您的脚本采用UNIX文件格式。正如@shellter通过评论指出的那样,您的脚本似乎不是UNIX格式。
注意:dos2unix script
将就地转换文件。