It seems like my shebang is being ignored. When I try to execute a shell script I wrote, I get an error:
% ls -alh /usr/sh
-r-xr-xr-x 1 root 1011 139k Sep 16 01:29 sh
% ls -alh foo.sh
-rwxr-xr-x 1 george george 21B Sep 16 00:59 foo.sh
% cat ./foo.sh
#!/usr/sh
echo "lol"
% ./foo.sh
./foo.sh: Command not found.
% sh ./foo.sh
lol
Yes, it's at /usr/sh. I put it there.
But as you can see it works just fine when I instruct sh
to execute it. What gives?
I don't think $PATH
is applicable but in some search results trying to solve this problem, people have asked for it:
% echo $PATH
/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:/root/bin
The reason for this can be one of several things. To list the most common:
chmod a+x foo.sh
to give all users execute permissions.which sh
and copy the result after a #!
\n
. Text editors such as nano
allow you to convert by choosing Write-out
then pressing Alt+D
to toggle DOS format off. Utilities such as dos2unix
can convert files directly on the command line (although it may need installing first).If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With