#!/usr/bin/env: No such file or directory - node.js

The shebang line in my bin/www file is:
pi:~/ferc$ head -n 1 bin/www
#!/usr/bin/env node
However, executing it:
pi:~/ferc$ bin/www
bin/www: line 1: #!/usr/bin/env: No such file or directory
The env file does exist:
pi:~/ferc$ ls -lL /usr/bin/env
-rwxr-xr-x 1 root root 31408 Feb 18 2016 /usr/bin/env
The node file also exists:
pi:~/ferc$ ls -al /usr/bin/node
lrwxrwxrwx 1 root root 15 Jul 7 18:29 /usr/bin/node -> /usr/bin/nodejs
And node runs fine:
pi:~/ferc$ node -v
v4.2.6
What does the error message really mean? Which file is it complaining about?

The cause was a corrupted file, probably due to a mixture of LF and CF/LF line endings in the file.
What happened were:
I copied the file from a Windows PC to the AWS ec2 Ubuntu instance.
First time I ran the www file, that same error message appeared. The cause at this point was probably the node executable did not exist. I hadn't created the symbolic link yet.
While trying to troubleshoot, I edited and saved the www file using nano. I think at this point the file got corrupted.
Later, I added the symbolic link for /usr/bin/node. However, the same error persisted, but probably due to the corrupted line endings.
I dos2unix the www file, and the error went away.

You can use node directly like:
#!/usr/bin/node
See pros and cons: https://unix.stackexchange.com/questions/29608/why-is-it-better-to-use-usr-bin-env-name-instead-of-path-to-name-as-my

Related

Bash scripts only run when using bash command

Today, my working bash scripts stopped working on my Debian 11 server.
$ ./CCrec.sh
-bash: ./CCrec.sh: Permission denied
Fails even if using sudo.
Yes, the permissions are set correctly. (They've been working for years.)
$ ls -l CCrec.sh
-rwxr--r-- 1 user1 user1 858 Jan 23 20:30 CCrec.sh
Another clue: autotab it doesn't recognize the script is present with beginning with "./". This makes me think the's a change in my bashrc, but I'm not noticing a change.
script will run when specifying bash:
$ bash CCrec.sh
This is working
Any solutions?

How to Create a path in my shell for windows?

I have a question, I created a script but I need to create a path, to find my cassandra folder to execute cqlsh, this is the route
C:/apache-cassandra-3.11.4/bin/cqlsh
the problem is because I am in windows not in linux, and I want to see if possible to create an a path in case that I need to pass my script to my team. but you know your cassandra db is in another route for that reason I want to do that because I need to execute this script
example
route= /../cassandra3.11.4/bin/cqlsh
$route -k fsainstqual -e "TRUNCATE instrumentmanufacturer"
If you mean you don't know how to mix Windows drive letters and Linux directory handling (which does not have drives), you'll need mounting points, as you can see in following mount excerpt on my PC, where I have a Linux app installed:
Prompt>mount
...
C: on /mnt/c type drvfs (rw,noatime,uid=1000,gid=1000,case=off)
E: on /mnt/e type drvfs (rw,noatime,uid=1000,gid=1000,case=off)
In top of that, on my root directory, I've created symlinks to those mounted directories:
Prompt>cd /
Prompt>$ ls -ltra | grep "\->"
lrwxrwxrwx 2 root root 6 Nov 23 2017 C -> /mnt/c
lrwxrwxrwx 2 root root 6 Nov 14 12:00 E -> /mnt/e
I think it's better to clarify your question buddy.
If you want to change your current directory, you can use "cd" command as in linux shell.
If you want to create a path use "md" or "mkdir" command.
Here is the help in windows OS
https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/md

"no such file or directory" after using SCP

I am using WSL Ubuntu-Bionic on my laptop and copied a file to a beaglebone (Debian-Stretch). Somehow it is shown by ls -l when I ssh onto the beagle, but if I try to run it, I get an error:
scp test debian#134.147.152.133:~/crosstest
ssh debian#134.147.152.133
ls -l
-rwxr-xr-x 1 debian debian 8936 Jan 8 09:50 crosstest
./crosstest
-bash: ./crosstest: No such file or directory
After searching around a bit, I found a solution:
As Romeo wrote, this had to have something todo with the file itself. I recompiled the file using arm-linux-gnueabihf-g++ instead of arm-linux-gnueabi-g++.
I found this after reading this SO post

Is it portable to call executable with full path "/bin/..."?

For the RTOS I'm writing ( http://www.distortos.org ) I need to run find as part of the build configuration process (from make menuconfig target). For Windows I assume that user has MSYS2 installed, so find.exe is available. The only problem with this particular file is that Windows also has such file in C:/Windows/system32 (supposedly it is something close to grep). So depending on the order of folders in your PATH environment variable you get one or the other if trying to call the file by just the name.
I've found that calling this program as /bin/find from the Makefile or in shell script works both in Windows and on (my) Linux. What is most important - doing it that way always calls find.exe from MSYS2, no matter what is the order of folders in PATH. So I'm wondering - is it OK to call find this way, or maybe it is not portable and I just had luck that it works for me?
It would probably be more portable to refer to it as /usr/bin/find. For example, on Fedora /bin is actually a symlink to /usr/bin, so either works:
bash-4.3$ ls -l /bin/find
-rwxr-xr-x. 1 root root 222608 Dec 28 18:26 /bin/find
bash-4.3$ ls -l /usr/bin/find
-rwxr-xr-x. 1 root root 222608 Dec 28 18:26 /usr/bin/find
But on a recent Ubuntu:
root#69ca68fbe5c0:/# ls -l /bin/find
ls: cannot access /bin/find: No such file or directory
root#69ca68fbe5c0:/# ls -l /usr/bin/find
-rwxr-xr-x. 1 root root 229992 Jan 6 2014 /usr/bin/find
I would recommend not hard-coding the path to find and instead instruct Windows users that they must run your script inside the MSYS2 environment. MSYS2 will put its own bin directories near the beginning of the path so that find always gets the MSYS2 version instead of the Microsoft version.
If you hard-code the path to find then you make things be more brittle than they need to be.

Running a nodejs file with "./" in terminal

How do I run a nodejs file using ./foo.js instead of node foo.js from the terminal? Running it with node works fine, but with the ./ I get bash: ./foo.js: Permission denied.
I'm new to Ubuntu, so I'm not sure if its an OS tweak.
Make sure the file is executable. You can check this by doing a "ls -la":
$ ls -la foo.js
-rw-r--r-- 1 daniel daniel 0 Oct 15 21:53 foo.js
The lack of an "x" means that it's not executable. To make it executable, use chmod +x:
$ chmod +x foo.js
$ ls -la foo.js
-rwxr-xr-x 1 daniel daniel 0 Oct 15 21:53 foo.js
Also make sure you have a "shebang" line at the very top of the file. This tells the shell what interpreter to use for the file:
#!/usr/bin/env node

Resources