“command not found” when running shell script

我怕爱的太早我们不能终老 提交于 2021-01-05 07:20:27

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!