Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux shell script not found, but it does exist

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?

like image 503
demonguy Avatar asked Aug 22 '26 20:08

demonguy


1 Answers

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.

like image 58
demonguy Avatar answered Aug 25 '26 12:08

demonguy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!