问题
Here is the simple script.sh
file I have:
#!/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.
回答1:
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.
回答2:
Also do not use a variable called PATH (cause it is already used :)
来源:https://stackoverflow.com/questions/43771597/command-not-found-when-running-shell-script