shell script: bad interpreter: No such file or directory when using pwd

后端 未结 11 1648
抹茶落季
抹茶落季 2021-02-07 09:30

I want to go through the files in a directory with a for loop but this comes up.

echo: bad interpreter: No such file or directory

code:

相关标签:
11条回答
  • 2021-02-07 10:04

    so, if you change your username group priority from username to root, you should change

    #!/user/bin/bash
    

    to

    #!/bin/bash
    

    check your user group (my username is rommi)

    $ groups rommi
    

    this command will output:

    rommi : root adm cdrom sudo dip plugdev lxd lpadmin sambashare
    

    since my username group priority is set to root, i should change my script to

    #!/bin/bash
    

    i change the priority group using:

    sudo usermod -g root rommi
    

    if groups rommi command outputs:

    rommi : rommi adm cdrom sudo dip plugdev lxd lpadmin sambashare
    

    then my script should use #!/usr/bin/bash

    fail make this changes will resutl in bad interpreter: No such file or directory error

    0 讨论(0)
  • 2021-02-07 10:07

    I had the same problem. Removing #!/bin/bash did the trick for me. It seems that is not necessary to add where bash is located, since it is on the system path.

    I found another solution here. Change

    #!/bin/bash

    for

    #!/usr/bin/bash

    0 讨论(0)
  • 2021-02-07 10:07

    In my case the bash script was created on a Windows PC which added a carriage return character in front of every line feed. \x0D\x0A instead of just \x0A. I replaced all the CRLF with just LF using the sed and my script works now.

    sed -i 's//\r/\n//\n/g' /path/to/file.sh
    
    0 讨论(0)
  • 2021-02-07 10:11

    I have followed the steps from the following link and issue has been resolved.

    Ref link: script error - bad interpreter Actually, there was an extra ^M symbol at the end of each line. So, after the removal of that, it worked fine for me.

    Hope it helps!

    0 讨论(0)
  • 2021-02-07 10:15

    If you did use Homebrew to install BASH,

    Removing the #!/bin/bash will be suffice.

    0 讨论(0)
提交回复
热议问题