Linux shell script not found, but it does exist

14,910

Solution 1

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.

Solution 2

Also worth checking that your shebang is correct, either: #!/bin/sh or #!/bin/bash

Share:
14,910
demonguy
Author by

demonguy

Updated on June 30, 2022

Comments

  • demonguy
    demonguy almost 2 years

    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?