'bash: No such file or directory when file is clearly present

I have a shell script located at "/home/pi/scripts/take-snapshot.sh" but when ever I try to execute it I get a error that the file is not present.

the following commands do not work (assuming in script directory):

/home/pi/scripts/take-snapshot.sh
./take-snapshot.sh
take-snapshot.sh
bash /home/pi/scripts/take-snapshot.sh

the following do work and will bring up the shell file (not a new file):

vi take-snapshot.sh
nano take-snapshot.sh


Solution 1:[1]

The most likely cause is that your file is not executable. Bash is a bit confusing in that it reports the file as "not found", even though you only don't have permissions to execute it. Run ls -l and check the permissions. The leftmost column should show an "x" at least for the current user. It will usually look something like -rwxr-xr-x for a file you have created yourself.

Run chmod +x take-snapshot.sh to fix the permissions if they don't match.

Solution 2:[2]

I have seen this error when the line endings are windows EOL characters. It doesn't give any other error, just the above "No file or directory".

Check the EOL character and convert it to linux EOL, if it is windows and try to run the script again.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 PMF
Solution 2 adbdkb