4 ms·
Note that /bin/bash isn’t completely portable (though /bin/sh is, that’s not Bash) as some systems have it at /usr/local/bin/bash.
by amarshall 6y ago
Note that /bin/bash isn’t completely portable (though /bin/sh is, that’s not Bash) as some systems have it at /usr/local/bin/bash.
- m463 6y agoThat's what i've learned... #!/bin/sh is generally what I use and it survives porting. If I need more power I usually switch to python. (Probably not relevant to a bash discussion though, sorry)
- laumars 6y agoYou’re just reiterating the GPs point of using env instead of calling bash directly from the shebang: #!/usr/bin/env bash is more portable than #!/bin/bash Though personally if I was worried about portability then I’d just write the script in vanilla sh instead.
- spurgu 6y ago> using env instead If this method is superior, why hasn't it caught on with Bash I wonder (it's considered standard with Python and Node at least)? > Though personally if I was worried about portability then I’d just write the script in vanilla sh instead. Agreed.
- laumars 6y ago> If this method is superior, why hasn't it caught on with Bash I wonder (it's considered standard with Python and Node at least)? Because if you need a portable bash then you target sh. But if you want a portable Python then you still target Python.
- josefx 6y ago> But if you want a portable Python then you still target Python I am still supporting systems that came with Python 2. You get portable Python the same way you get portable bash: build and deploy the interpreter with your code.
- laumars 6y agoYou’re missing my point. If you’re targeting Python then you need Python installed however you don’t always know where that executable might live. Whereas if you’re targeting shell scripts then you can always fallback to regular Bourne shell if you need portability and that should always have an executable or simlink in /bin/sh. The Python 2 problem is a whole other topic :)
- amarshall 6y agoIndeed; looking back I misread the “>” is directional (e.g. ->) rather than comparative.
- shakna 6y agoI believe this statement agrees with you: > #!/usr/bin/env > #!/bin/bash for portability Perhaps you misread it? env bash is greater for portability than bin/bash.
- jhardy54 6y agoOh, I misread that as an arrow pointing from 'before' to 'after'. Makes sense now!
- williamdclt 6y agoYou're not the only one, I spent a minute thinking about a discussion explaining why the `env` way was better, I was going to have a rant about people giving contradictory advice for "portability"!
- amarshall 6y agoYup! I misread the “>” is directional (e.g. ->) rather than comparative.