0

I wrote a simple .sh file to be executed on an Alpine Linux environment. Contents as below

#!/bin/sh

echo "Hello World"

But I'm always getting this message while trying to run

localhost:/opt# ./helloWorld.sh
-ash: ./helloWorld.sh: not found

localhost:/opt# getfacl helloWorld.sh
# file: helloWorld.sh
# owner: root
# group: root
user::rwx
group::r-x
other::r-x

Not able to figure out what I'm missing here to make this work. Any leads or help would be greatly appreciated. Thanks in advance.

VikramV
  • 1,111
  • 2
  • 13
  • 31
  • Your file is almost certainly saved with DOS newlines. That means it's trying to use `$'/bin/sh\r'`, not `/bin/sh`, and no interpreter by that name (which is to say, with a name ending in a literal carriage return) exists. – Charles Duffy Apr 26 '20 at 23:44
  • @CharlesDuffy: Look at the wording of the error message: It is produced by _ash_, so I guess the OP runs ash as his interactive shell (which is odd, but not forbidden), and then upon entering the relative path to the script, ash complains that it does not find the script. It does not even come to the point examining the `#!`. IMHO, the OP simply saved the script under a different path. – user1934428 Apr 27 '20 at 06:40
  • @VikramV : Please show also the output of `ls -l ./helloWorld.sh`. – user1934428 Apr 27 '20 at 06:41
  • @VikramV : Knowing the output of `file ./helloWorld.sh` would also help, in order to evaluate what Charles Duffy suspected. – user1934428 Apr 27 '20 at 06:43
  • 1
    @user1934428, `getfacl` output rules that out just as well. Being unable to find an interpreter causes the `execve` syscall to throw the error given, so it's not unexpected for the interactive shell (being the program that's calling `fork` and then `execve`) to throw that error. – Charles Duffy Apr 27 '20 at 13:31

0 Answers0