0

I've been mostly using Manjaro and Arch recently, but I'm trying to debug some possible hardware issues on Mint.

I have a number of bash scripts that no longer work in mint, because they start with #!/usr/bin/bash, but Mint has bash located at /bin/bash. Is there a way to incorporate some sort of redirect without having to change all my scripts?

For example, one of my first scripts I wrote to start practicing was just this:

#!/usr/bin/bash -x
cmatrix -bC red

Removing the /usr portion allows it to run fine in Mint, but is there a way to keep the same script and run it in both distros?.

0
2

There’s a relevant Q&A on Stack Overflow, See What is the preferred Bash shebang?, but I can’t find a good one here.

If you want your script to find bash anywhere on the PATH, whether /bin, /usr/bin, etc., use

#!/usr/bin/env bash

(This assumes /usr/bin/env exists.)

On most Linux distributions though, including those you mention, it’s safe to use

#!/bin/bash

Some distributions also have /usr/bin/bash, but that’s the result of the /usr merge”/bin and /usr/bin now have the same contents in these distributions.

1
  • Yeah, I was hesitant to post on Stack Overflow as it seems more of a Linux thing than a scripting thing. If anything, I suppose I could put a symlink to direct per distro if the other one doesn't like the change. – Asinine Jun 17 '20 at 19:30
0

The following will require a one time change. #!/usr/bin/env bash will search your PATH for bash. You'll have to set -x separately though.

2
  • Sorry, not sure how that helps? This is my echo $PATH output: $ echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games Edit: I was going to post on stackexchange, but I thought this was a distro issue. Should I head over there instead? – Asinine Jun 17 '20 at 1:51
  • You can have multiple versions of bash on a server. Production scripts may want to use the bash that comes installed on the server and you may want a newer version of bash for other scripts. For a detailed discussion, Take a look at stackoverflow.com/questions/16365130/… – rr0ss0rr Jun 18 '20 at 2:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.