> Will this script ever run anywhere that I don't have the GNU toolchain? Effectively-0% likely.
Not really. A lot of stuff broke when /bin/sh moved to a POSIX-compatibile shell rather than Bash.
No a lot of stuff broke because people depended on implicit rather than being explicit.
#!/bin/bash wilya@home $ /bin/bash
zsh: no such file or directory: /bin/bash
wilya@home $ which bash
/usr/local/bin/bash
(Yes, I'm annoyed when I see #!/bin/bash, especially on scripts which are otherwise basic enough to be portable everywhere)It is still better to write #!/bin/bash for bashism using scripts than #!/bin/sh. I recently had to run sed -i (well, another GNUism) 1s%/sh%/bash% on bunch of customer's scripts to make them work on debian. At least when script wants /bin/bash it is going to fail cleanly (and not in the middle after modifying random things) and with mostly meaningful error.
It's probably safer to use:
#!/usr/bin/env bash
Assuming env is installed (I believe I had to install a package on OpenBSD to use it) this will find the first instance of bash in the PATH.How do you know env is in /usr/bin rather than in /bin or /usr/local/bin? I'm just curious...
You don't, but I've run into more problems with bash being in unexpected places than env.
Right on, thanks.
Good question. I've used systems, e.g. AIX, where env(1) was in /bin.
And now porting your script to non GNU such as BSD becomes a pain in the behind ... whereas before maybe only one or two commands would have had to change, now it will be most if not all.
When I mentioned "GNU", I think it sort of implied that I am aware of the existence of non-GNU toolchains.
I really am not worried about that in my world. The dependencies on Linux go a great deal deeper than the GNU toolchain. YMMV.
Re:Use long flags when scripting
by papsosouid on Monday February 04, 2013 @02:39PM
(#5166531)
>Will this script ever run anywhere that I don't have the GNU toolchain? Effectively-0% likely.
That's not the case for most people though. I can't even remember the last time I saw even a tiny project assume the world is all "whatever gnu/linux distro I happen to use". Tons of people use linux distros that aren't ubuntu, tons of people use OSX, tons of people use a BSD.
"Will I ever have to read and modify this script again? Effectively-100% likely. Will this script ever run anywhere that I don't have the GNU toolchain? Effectively-0% likely."
It's a no-brainer at that point.
If you can't say that second part honestly, reconsider, but a lot of us can.