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
jsfiles have the BOM and Windows line endings and they work fine. – u936293 Feb 13 '19 at 06:08.jsfiles are being read by a running Node process, which doesn't have problems with BOMs and Windows line endings. The script you're having problems with starts that Node process, and is therefore read by the Linux kernel to determine how to run it. That's why it has to play by Unix rules: ASCII shebang line, no BOM or prepended space, Unix line ending (the kernel ignores everything after the shebang line). – Adrian Feb 13 '19 at 06:17