Silent_Rebel Silent_Rebel - 5 months ago 17
Linux Question

shell script throwing No such file or directory error while command line works perfect

I am trying to run a simple piece of shell script which return No such file or directory while executing the statement from command line works perfect.

Any leads ??

#!/bin/bash
cat /home/dev/.bashrc


I am executing the code like
bash ~/Desktop/test.sh

Answer

You have a \r at the end of /bin/bash so it's trying to run /bin/bash\r which does not exist. Use just \n to terminate lines, like from a dos2unix tool or similar if you have it available.

That will also fix the \r at the end of your /home/dev/.bashrc

The \r in the shebang line isn't actually coming into play yet because you're invoking it as bash test.sh so it isn't using it, but it's the same problem

Comments