# /bin/bash: bad interpreter: No such file or directory



## Deleted member 63539 (Aug 14, 2020)

Porting a software from Linux (for personal use, not planned to put it in ports). Should I just create a symlink or fix their shell scripts? There are too many of them to edit by hand. Someone with scripting skills please help me writing a script to convert all of these #!/bin/bash to #!/usr/bin/env bash. I think it will involve sed or awk, and I don't want to deal with both of them. Thank you very much.


----------



## SirDice (Aug 14, 2020)

Porter's handbook: 17.81. shebangfix


----------



## Alain De Vos (Aug 14, 2020)

Is , "ln -s /usr/local/bin/bash /bin/bash", insufficient ?


----------



## Deleted member 63539 (Aug 14, 2020)

Alain De Vos said:


> Is , "ln -s /usr/local/bin/bash /bin/bash", insufficient ?


I asked very clearly in my first post here about should I just use the symlink workaround or fixing it. Since currently I'm only keep it for myself, but who know if someday I contributed it to ports or even attempt to get the upstream project to merge my fixes?


----------



## Deleted member 63539 (Aug 14, 2020)

SirDice said:


> Porter's handbook: 17.81. shebangfix


Currently I don't utilize the ports system. Could you give me a shell script? Thank you.


----------



## a6h (Aug 14, 2020)

gh_origin said:


> Could you give me a shell script?




```
#!/bin/sh
sed -i '' "1 s/^.*$/#!\/usr\/bin\/env bash/" *
```


----------



## memreflect (Aug 16, 2020)

gh_origin said:


> Could you give me a shell script?




```
#!/bin/sh

# Sample usage:
#     /path/to/script.sh ./.bash_scripts ./src/bash_helpers
# Will work recursively, thanks to find(1).
# Will ignore paths containing a path component with
# a leading dot (e.g. .git, .svn, .bashrc).

set +f &&
        find "$@" -type f -path '*/[!.]*' -print0 |
            xargs -0 \
              sed -i'' \
                '1s%^#!.*/bin/bash[[:blank:]]*$%#!/usr/bin/env bash%'
```
Not POSIX portable in the least (what with all the `-print0` and `-0` and `-i''`), but it works on FreeBSD and should also work on any Linux distro as far as I'm aware (and NetBSD and OpenBSD as far as I can tell from their man pages).


----------

