2

I have just created an Ubuntu 18.04 instance on AWS and copied an existing project over. The usual shebang line for Node #!/usr/bin/env node now doesn't work. It gave:

 #!/usr/bin/env: No such file or directory

What could be wrong?

My $PATH variable is:

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

which node gives: /usr/bin/node

which nodejs gives /usr/bin/nodejs

ls -l nodejs gives: /usr/bin/nodejs -> /etc/alternatives/nodejs

ls -l /usr/bin/env gives:

-rwxr-xr-x 1 root root 35000 Jan 18  2018 /usr/bin/env
u936293
  • 731

1 Answers1

2

The script that gives this error message got mangled somehow. For instance, if you did some touchup of your script in a Windows editor before shipping it to your AWS instance, your script now likely starts with a non-printing BOM before the shebang, and maybe all your script's lines now end in Microsoft's favorite CR-LF combo instead of the traditional Unix LF.

Check the output of this command on your AWS instance:

$ LC_ALL=C sed -n 1l myscript.sh

That tells sed to print the first line of your script, but escape all non-printing characters and end the line with a $ character (in case there are invisible spaces at the end of the line).

There's only one correct output:

#!/usr/bin/env node$

If what you see doesn't look exactly like that, run the same command on your original myscript.sh. If you get the same result, fix it there, then copy it over to AWS again.

Adrian
  • 166