bash 运行shell脚本时“找不到命令”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43771597/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"command not found" when running shell script
提问by Axel Finkel
Here is the simple script.sh
file I have:
这是script.sh
我拥有的简单文件:
#!/bin/bash
pwd
date
ls -lg
I have used chmod +x
to make the file executable, but when running it with ./script.sh
I get command not found: pwd
command not found: date
and only the ls -lg
command works. I'm a bit perplexed as to why the first two commands aren't working because when I type them into the command terminal they work the way they should.
我曾经chmod +x
使文件可执行,但是当./script.sh
我使用 get运行它时command not found: pwd
command not found: date
,只有ls -lg
命令有效。我有点困惑为什么前两个命令不起作用,因为当我在命令终端中输入它们时,它们会以应有的方式工作。
回答by Jamil Said
Maybe there is a (invisible) character there that should not be there. Try typing it again from scratch in the environment that it will run (ex: Linux) or use this command od -c /folder/script.sh
to reveal those pesky characters.
也许那里有一个(隐形)角色不应该在那里。尝试在它将运行的环境(例如:Linux)中从头开始再次输入它,或者使用此命令od -c /folder/script.sh
来显示那些讨厌的字符。
回答by Michael K?fer
Also do not use a variable called PATH (cause it is already used :)
也不要使用名为 PATH 的变量(因为它已经被使用了 :)