Linux shell script not found, but it does exist

demonguy picture demonguy · Dec 3, 2014 · Viewed 12.1k times · Source

I created a shell script "/etc/aaa" on Openwrt which contains the following code: #!/bin/sh echo "Hello World!"

I also used this command to ensure the proper permissions:

chmod 777 /etc/aaa

Upon executing with any of the below 2 commands

sh /etc/aaa

or

ash /etc/aaa

it works well and prints "Hello World". The problem occurs when I try to execute it with this command:

/etc/aaa

where I get this error:

-ash: /etc/aaa: not found

Can anyone please explain why this is happening? What am I missing here?

Answer

demonguy picture demonguy · Dec 6, 2014

Thanks for Charles Duffy's comment. It's really the CR LF problem. Though i open the file in my linux virtual machine, since it has been modified in Windows. so enven in linux, the sublime text editor i use will think it's a windows file and use crlf as newline ending.

So ,just replace crlf with lf , the problem solved.