4 ms·
I suggest you read the accepted answer at http://stackoverflow.com/questions/19428418/what-is-the-use-of-portable-shell-scripts http://stackoverflow.com/questio
by stephenr 12y ago
I suggest you read the accepted answer at http://stackoverflow.com/questions/19428418/what-is-the-use-of-portable-shell-scripts http://stackoverflow.com/questions/19428418/what-is-the-use-... for a brief look at why portable shell scripts are a better solution than bash specific scripts.
- eropple 12y agoI suggest you read my post and maybe let it roll around your head that I've considered my environment and the domain of my problems in a way you aren't giving me credit for. Perhaps even, with that whole mention of devops, I do something such as--crazy thought incoming--install an updated version of bash on every system I must provision, just as I do Ruby, Python, etc.? "Decent shell script" is not a synonym for "portable shell script" and the presumption therein is what I was addressing.
- sigzero 12y agoExactly so. If I want PORTABLE, I write to "sh". If I want BASH, I write to BASH. The term "decent shell script" is wrong the way he uses it.
- mysidia 12y agoPerhaps he didn't deliver the point... but BASH is not a good or safe language to write to. Writing to '/bin/sh' is understandable due to its ubiquitousness. Bash is a superset that is not so ubiquitous, so it doesn't have the advantage that writing to /bin/sh does. If you don't want portable, then don't write to shell script. Write to Perl Ruby or Python, which is also safer and more secure.
- eropple 12y ago/bin/bash is on literally every machine I ever touch. It is on every Debian machine. It is on every Ubuntu machine. It is on every OS X machine. It is on every Windows (!) machine. And there are plenty of operations that are significantly more cumbersome to write in Ruby--otherwise, sure, I would do so. Backticks are nice, but there's no `set -e` (that I am aware of) and it becomes a huge hassle to do things in a smart, error-checking way.
- lutusp 12y ago> /bin/bash is on literally every machine I ever touch. It is on every Debian machine. It is on every Ubuntu machine. It is on every OS X machine. It is on every Windows (!) machine. Yes. Yes. Yes. Yes. No (unless Cygwin is installed).
- eropple 12y ago/bin/bash is on literally every machine I ever touch. Did you miss the operative phrase? (I have init scripts for Cygwin, too, because I need Windows but life is too short for CSRSS.)
- lutusp 12y ago> /bin/bash is on literally every machine I ever touch. Did you miss the operative phrase? You intended that subjunctive clause to apply to all the sentences, an intent I missed. My mistake. :) This may soon become a tempest in a teapot, as patched Bash versions are now appearing. I just patched all my machines.
- stephenr 12y agoNo-one claimed Bash isn't widely distributed and installed by default. However, unless you are patching and compiling the same version of Bash, you absolutely do not have the same version on all those machines, and that is the whole reason NOT to target Bash in shell scripts - its features are not always consistent/compatible across versions.
- stephenr 12y ago> "Decent shell script" is not a synonym for "portable shell script" Only for you. For me and a lot of others I suspect, if it isn't portable it isn't worth the trouble. If you have to re-compile a newer/older version of a shell to get the same results across machines, any potential benefits start to seem insignificant compared to the effort involved.
- eropple 12y agoHow? I already am running Chef on every machine I touch.
- stephenr 12y agoSo you have a chef recipe to download and compile the same version of bash on every platform you use? How do you handle situations where bash is included by default? Do you remove the package or just push your binary over the top? If you don't remove it, what happens when a package update then replaces your binary? How often do you update the recipe to make sure it's getting the latest stable version and applying security patches?
- SamReidHughes 12y agoGosh, you are so clever.
- eropple 12y ago> So you have a chef recipe to download and compile the same version of bash on every platform you use? No, I have a chef recipe to install the newest version of bash 4 everywhere. How is an implementation detail. (I use Ubuntu packages and Homebrew, I only compile on cygwin.) > How do you handle situations where bash is included by default? Do you remove the package or just push your binary over the top? On OS X, the only place that's the case, I replace the binary (by using the Homebrew-compiled one). > How often do you update the recipe to make sure it's getting the latest stable version and applying security patches? I've written the Chef recipe to not need regular updates. I run my Chef update stuff on a weekly basis. I can do so manually if I need to.