“找不到命令";运行shell脚本时 [英] "command not found" when running shell script
问题描述
这是我拥有的简单的 script.sh
文件:
Here is the simple script.sh
file I have:
#!/bin/bash
pwd
date
ls -lg
我已经使用 chmod + x
来使该文件可执行,但是使用 ./script.sh
运行该文件时,却找不到 command: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.
推荐答案
也许那里有一个(不可见的)字符,不应存在.尝试在将要运行的环境(例如Linux)中从头开始再次键入它,或使用此命令 od -c/folder/script.sh
来显示那些令人讨厌的字符.
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.
这篇关于“找不到命令";运行shell脚本时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!