News for hackers. Stuff that matters.
Re:Shell Style Guide by Sir_Cmpwn on Tuesday May 15, 2018 @09:05AM (#17073600)
>Bash is the only shell scripting language permitted for executables.

Whelp, wrong right off the bat.

I'm gonna get down my my knees here and beg everyone reading: use POSIX shell. Do not write scripts with bash. Do not write scripts with zsh. Do not write scripts with fish. Use POSIX shell.

sh has a really bad interactive mode (so does bash), so I'm not gonna give anyone a hard time for using another shell as their day-to-day interactive shell. But, for the love of god, write your scripts with POSIX sh.

Re:Shell Style Guide by moviuro on Tuesday May 15, 2018 @09:45AM (#17073848)
> >Bash is the only shell scripting language permitted for executables.

> Whelp, wrong right off the bat.

It really is a Google guide, tailored to Google engineers. If they know for sure that bash is available on any *n?x machine, then why not? It's just a local policy.

And if it's that much of a problem, the other places where you get bash instead of POSIX sh from Google (chromium?) the license clearly allows you to rewrite said script to suit your needs.

All other points are valid though.

Note that I chose to write all my scripts in POSIX (e.g. https://gitlab.com/moviuro/moviuro.bin).

Re:Shell Style Guide by Sir_Cmpwn on Tuesday May 15, 2018 @10:12AM (#17074023)
>It really is a Google guide, tailored to Google engineers.

And posted in a public forum, which is why I made sure to protest its adoption by the broader public.

Re:Shell Style Guide by alecbenzer on Tuesday May 15, 2018 @11:01AM (#17074426)
I don't get that from "Whelp, wrong off the bat", which seems to imply that there is a more unambiguous right answer here, and Google is wrong for deviating from it.
Re:Shell Style Guide by Sir_Cmpwn on Tuesday May 15, 2018 @11:03AM (#17074443)
Well, even within Google I think this policy is stupid. Any software they make open source or have to port to new platforms that was based on this policy is going to break, and for what? Bashisms provide a dubious value-add.
Re:Shell Style Guide by reacweb on Tuesday May 15, 2018 @09:44AM (#17073842)
I have the opposite opinion. I have seen developers proudly putting /bin/sh instead of /bin/bash, without any other shell to test. When the script was run on ubuntu instead of redhat, this called dash and we discovered that the script was finally not compliant on subtle details. Writing POSIX compliant scripts is harder. Where is the reward when bash is present (almost) everywhere?
Re:Shell Style Guide by Sir_Cmpwn on Tuesday May 15, 2018 @09:48AM (#17073865)
>Where is the reward when bash is present (almost) everywhere?

It's really not. It's only present on some desktop Linux distributions. It's not present on almost any other OS or anywhere in the embedded space. POSIX shell, on the other hand, is everywhere.

Re:Shell Style Guide by pas on Tuesday May 15, 2018 @10:41AM (#17074237)
Why wouldn't you install Bash then, if you want to run shell scripts on those platforms?

I mean, what are the use cases? Where universality is important (so let's say when someone embeds scripts in Makefiles), I understand the need for POSIX, but other that I can't even come up with a good use case for having sh as default. (Maybe to save space, you ship the embedded device or Docker container with sh, sure, but then what kind of script you'd want to run there? Okay, maybe all of them, but then even on alpine installing bash is one quick command.)

Re:Shell Style Guide by saagarjha on Tuesday May 15, 2018 @01:24PM (#17075702)
> Why wouldn't you install Bash then, if you want to run shell scripts on those platforms?

Busybox is a thing. Many embedded devices don't have the luxury of installing Bash–you're stuck with what you've got.

Re:Shell Style Guide by pas on Wednesday May 16, 2018 @05:31PM (#17086680)
But what would a script do in such a limited situation? There are a lot of narrow use cases, but those are very much platform dependent, so no reason to use POSIX everywhere. Use whatever is best on that specific busybox thing.
Re:Shell Style Guide by Sir_Cmpwn on Tuesday May 15, 2018 @10:58AM (#17074394)
>but then what kind of script you'd want to run there? Okay, maybe all of them

I think you answered your own question here.

I can elaborate, though. bash isn't portable, it uses Glibc-isms. It has to be explicitly ported to new platforms. I also pointed out elsewhere that the value-add of bash is dubious at best - if you need to use bashisms you're better off not writing a shell script at all. So really, the question is: why do you need bash? You have to justify using non-standard tools, not the other way around.

Re:Shell Style Guide by pas on Tuesday May 15, 2018 @11:21AM (#17074591)
The mentioned "file transfer shell-program" somehow was so important that it has to run on AIX and Linux and every other OS under the sun, yet it was somehow not important enough to be written in non-sh.

And I feel the same with targeting POSIX sh.

Unless you have a really good business niche - like the aforementioned ftp script, use a proper language.

Yes, sysadmins were opposed to installing Bash. But if your core product depends on Bash and only on Bash, maybe I'd be opposed to everything about that deployment too.

And at the same time, I understand that there are IT tasks well suited to be solved with a script. But those don't seem to be the ones that require uber-portability.

If I need to setup something on a fleet of VMS-es, I'll use whatever I can get away with (including a lot of controlled substances to handle the dread of handling VMS), and won't think about what happens if we port this to HP-UX in the year 2525.

Re:Shell Style Guide by Sir_Cmpwn on Tuesday May 15, 2018 @11:28AM (#17074657)
There are many, many cases where a shell script is appropriate. I don't see a shell script as inherently evil, especially if you use one as conservative as POSIX sh. I ship shell scripts with my software often and for a wide variety of tasks.
Re:Shell Style Guide by susam on Tuesday May 15, 2018 @10:32AM (#17074163)
> POSIX shell, on the other hand, is everywhere.

Indeed! The significance of this, I believe, is underappreciated.

During 2008-2015, when I used to work for a network security company, we had a file transfer script[1] for Unix and Linux systems. It was written entirely as a shell script. It began as a simple wrapper around the scp and sftp commands for which a shell script was appropriate. The fact that every Unix and Linux system comes with a shell meant that we could ship a single file to all target Unix and Linux systems without requiring the administrator to install any new packages. The alternative was writing the file transfer functionality in C or C++ which would have required us to build and test the solution for every possible Unix system that our customers used or writing it in Java which would have required us to require the customer to install JVM on their systems. Many customer admins were averse to installing any additional packages on their systems. Given these constraints, a shell script was a good solution.

Unfortunately, the initial shell script relied on several bashisms.[2] Some customers began complaining that their Solaris or AIX system did not have bash, and they needed the script to work with Bourne shell or Korn shell. The customers refused to install bash. So I decided to clean up the script, remove all bashisms from it, and ensure that only POSIX specified features were used, only POSIX specified commands were invoked with POSIX specified options only (with the exception of the scp and sftp commands of course because that was the primary reason why the customers wanted the script).

I am not fond of bashisms. If I need bashims like arrays or regex substitutions in parameter expansions, it's a sign that the script is becoming complex and I switch to a modern programming language. These days, when I write a shell script[3], I restrict myself to POSIX.2001 (2004 edition)[4], write unit tests to exercise every line of code, run the unit tests with bash, ksh, zsh, dash, posh, and yash on Debian, run the tests with bash, ksh, and zsh on macOS, and use Kcov[5] to measure test coverage.

[1]: https://community.rsa.com/docs/DOC-53124

[2]: https://mywiki.wooledge.org/Bashism

[3]: https://github.com/susam/vimer

[4]: http://pubs.opengroup.org/onlinepubs/009695399/

[5]: https://github.com/SimonKagstrom/kcov

Re:Shell Style Guide by JdeBP on Tuesday May 15, 2018 @03:51PM (#17077228)
Note that there are several variants of the Korn shell. And there are even more shells than that.

You can test ksh93 and the MirOS Korn shell on Debian. For the Heirloom Bourne shell, though, look to FreeBSD, which has everything except the Watanabe shell.

* https://svnweb.freebsd.org/ports/head/shells/heirloom-sh/

* https://svnweb.freebsd.org/ports/head/shells/pdksh/

* https://svnweb.freebsd.org/ports/head/shells/ksh93/

* https://svnweb.freebsd.org/ports/head/shells/mksh/

* https://svnweb.freebsd.org/ports/head/shells/oksh/

* https://svnweb.freebsd.org/ports/head/shells/dash/

* https://www.freebsd.org/ports/shells.html

I appreciate what this sort of thing involves, as you can infer. (-:

* https://unix.stackexchange.com/a/434839/5132

Re:Shell Style Guide by chubot on Tuesday May 15, 2018 @11:38AM (#17074760)
Yes exactly, I had this experience and wrote about it here:

http://www.oilshell.org/blog/2018/01/28.html#limit-to-posix

Re:Shell Style Guide by liveoneggs on Tuesday May 15, 2018 @10:50AM (#17074324)
bash is slower and having it as /bin/sh was how so many (so so many) servers were taken over via shellshock
Re:Shell Style Guide by scbrg on Tuesday May 15, 2018 @10:17AM (#17074059)
A factor two or three in memory consumption.
Re:Shell Style Guide by jon-wood on Tuesday May 15, 2018 @09:16AM (#17073653)
I'm genuinely curious, why? If you're writing generic scripts designed to run across multiple platforms then fine, but in the context of Google (or most other companies) they'll have a standard set of tooling available on all their machines, which presumably includes Bash if they're making that statement.

What about POSIX shell makes it superior for scripting?

Re:Shell Style Guide by simias on Tuesday May 15, 2018 @09:25AM (#17073706)
I don't feel as strongly about it as Sir_Cmpwn does but I agree with him. The logic goes something like: you should only use shell scripts for small scripts and not complex applications. Ergo the added functionality of bash scripts should not be necessary anyway and might actually lead you to believe that it's a proper programming language.

Or to put it the other way around: if you find yourself writing a POSIX shell script and find that you'd like to use more advanced features then one of two things can happen:

- You need portability to SunOS 4, so you suck it up and keep hacking your script because bash is not an option anyway;

- You don't need portability, so then why not use a proper programming language like python, perl or ruby rather than upgrading from crappy sh to slightly-less-crappy bash?

Re:Shell Style Guide by avar on Tuesday May 15, 2018 @09:48AM (#17073868)
This logic is insane. This is like a company that mainly does C++ or Java saying that if you must use a scripting language it must be Tcl, not Perl or Python, least you get too comfortable with it.

If you want a policy against shellscripts growing out of hand have a policy against that, not that you must use the lowest common denominator even though you have Bash everywhere.

And I'm saying this as someone who almost exclusively writes POSIX sh for portability reasons, but my software isn't meant to target just Google's infra.

Re:Shell Style Guide by simias on Tuesday May 15, 2018 @10:30AM (#17074143)
I think it would be perfectly sane for a company to dictate which scripting language their environment will support. Shell scripts are a bit different though because if you write a large enough software system on a unix-like OS you'll probably want to write a few shell scripts here and there to glue things together, so forbidding them completely would be a bit silly and counterproductive. Saying "avoid shell scripts, if you really have to write one it must be simple and use POSIX sh" is not particularly insane to me.

But anyway my argument was more about my opinion about a developer talking for myself, not a company style guide. Life's too short to learn two shell dialects so I can either learn POSIX which will work basically everywhere and will let me write any simple script just fine or write Bash whose added complexity I probably won't need or even want.

The fact that I'm an embedded dev probably biases my view though, I generally target environments where bash isn't an option anyway.

Re:Shell Style Guide by Sir_Cmpwn on Tuesday May 15, 2018 @09:24AM (#17073703)
Google also makes it difficult to compile Chromium on platforms where /usr/bin/python is python 3, because their shebangs are:

    #!/usr/bin/env python
Rather than the more portable:

    #!/usr/bin/env python3
Notably this causes problems for people on Arch Linux, and in the near future, Fedora. This post is presented as a style guide that others should adopt. Google may have bash ubiquiotously available internally, but their approach should not be taken as a model for others. Google's approach has caused real problems for their software's portability in exchange for dubious value-adds.

>What about POSIX shell makes it superior for scripting?

To address this specifically, I have written a blog article on the subject:

https://drewdevault.com/2018/02/05/Introduction-to-POSIX-she...

The main points are:

- bash is far from as ubiquitous as some people seem to think it is

- sh is formally standardized and has multiple competing implementations, whereas bash is defined by its implementation and there is only one

- sh is perfectly competent and easy to target, bash's value add is questionable

- By the time you need the things bash offers you might as well not use a shell script at all

Re:Shell Style Guide by mort96 on Tuesday May 15, 2018 @10:04AM (#17073970)
If you find yourself compiling Google-stuff a lot on Arch, you might find this useful: https://github.com/mortie/nixConf/blob/master/bin/py2

I wrote that script exactly because of the issue you described, and I got tired of changing what /usr/bin/python is symlinked to constantly. With that script, I just run `py2 gn gen out/Debug` or whatever, and my /usr/bin/python stays intact so everything else which expects python3 works, and only the `gn` process and all subprocess sees python2.

This definitely doesn't excuse Google's behavior, but I don't expect it to be fixed soon. My bug report about it (https://bugs.chromium.org/p/webrtc/issues/detail?id=7376) was closed as wontfix (though I'm not entirely sure the person who closed it understood that I was asking for the python scripts to explicitly use python 2, not for them to port the scripts to python 3).

Re:Shell Style Guide by moviuro on Tuesday May 15, 2018 @10:09AM (#17074012)
Clearly the WONTFIX was wrongly issued. The issue should be re-opened.
Re:Shell Style Guide by chrisfinazzo on Tuesday May 15, 2018 @10:24AM (#17074099)
The python v python3 thing is their (Py's implementers) own stupid fault; although the argument could be made that they didn't have any choice.

People have been on 2.7 for so long that a breaking change might be the only thing to get them to move over.

As Chromium is open source, I'm surprised they haven't really explained how people outside of the Googleplex should handle this.

Seems like they're left to their own devices.

Re:Shell Style Guide by hyperpape on Tuesday May 15, 2018 @01:39PM (#17075875)
I believe your claim that

  /bin/sh 
is standardized is incorrect, though I don't know how many actual systems fail to have it present. Source: https://news.ycombinator.com/item?id=17069408 (I checked the 2018 version of the spec, and it says the same).
Re:Shell Style Guide by Sir_Cmpwn on Tuesday May 15, 2018 @01:50PM (#17076016)
Aye, I was incorrect. I have pushed a correction, but it will take a moment to appear on the site.
Re:Shell Style Guide by joshuamorton on Tuesday May 15, 2018 @10:42AM (#17074246)
The second thing is not more portable than the first (unfortunately).
Re:Shell Style Guide by Sir_Cmpwn on Tuesday May 15, 2018 @10:51AM (#17074334)
Re:Shell Style Guide by joshuamorton on Tuesday May 15, 2018 @10:59AM (#17074402)
That, unfortunately, only works if you don't need to maintain backwards compatibility with older systems. `python` will exist and point to python2 on any system. `python2` may not if it predates or ignores the PEP. `python3` didn't even come installed by default on a lot of nixes until recently, making it the worst of option of the three.
Re:Shell Style Guide by Sir_Cmpwn on Tuesday May 15, 2018 @11:01AM (#17074428)
Of course, it will take time for this to become effective. But this is the portable solution. Systems for which this does not work are broken and should be fixed, software should not be updated to accomodate for broken systems.
Re:Shell Style Guide by joshuamorton on Tuesday May 15, 2018 @11:18AM (#17074569)
>software should not be updated to accomodate for broken systems.

Its not. The software was written, and maintains, backwards compatibility with systems that predate or partially predate the spec. The spec was written to be backwards compatible with those systems. Using the backwards compatibility option is correct if you wish to maintain backwards compatibility. Consider that Arch also technically violates Pep 394,

> for the time being, all distributions should ensure that python, if installed, refers to the same target as python2

We shouldn't update the shebangs in all of our software ever to accommodate a misbehaving, spec-non-compliant distro, should we?

Re:Shell Style Guide by wildmusings on Tuesday May 15, 2018 @09:32AM (#17073766)
Competing implementations sounds like a potential downside to me. That’s just more possible configurations where a bug could be hiding. Even if you use standard posix shell, you’d be wise to target a single implementation and stick to it.
Re:Shell Style Guide by _jal on Tuesday May 15, 2018 @09:48AM (#17073869)
This is exactly backwards. If you don't have separation of specification and application, you don't have a specification.

I mean, standards aren't necessary; interpreters can absolutely be snowflakes. But multiple implementations is a sign of strength, and intentionally targeting the bugs of one implementation is short sighted, if sometimes required.

Re:Shell Style Guide by Sir_Cmpwn on Tuesday May 15, 2018 @09:37AM (#17073791)
So you think that competition between gcc and clang is harmful to the C and C++ ecosystems? If you find bugs in an implementation of POSIX sh, you should report it to that implementation. Multiple competing implementations is a sign of a good standard, it proves the standard's correctness and demonstrates its maturity.

There is no standard to hold bash to. Any strange behavior of it might be decided as by design and kept forever (and replicated by anything which tries to be bash compatible) or it could be determined to be a bug and, when fixed, break the scripts which worked around it or depended on it. There's no way to know how this is going to shake out because there is no objective specification for the language. At least when there's a bug in one of these competing sh implementations that you're so worried about, it's objectively a bug and can be fixed.

Re:Shell Style Guide by wildmusings on Tuesday May 15, 2018 @09:50AM (#17073892)
To be more precise, my point was that you should only be targeting one of the implementations anyway. I don't see how it's a good use of people's time to be testing their scripts against every shell that claims to be sh-compatible, especially at a place like Google where the scripts are almost all being written to run on completely Google-controlled environments.

But I didn't think about the bug vs. by-design issue and how that is remedied by a well-defined standard. That does seem to be a factor in favor of using a standardized language. But it doesn’t seem different in principle than depending on any software. It is liable to change and leave you with a difficult decision of forking the library or modifying your code that consumes it. Given bash’s ubiquity, it seems reasonable to expect a good level of stability.

If you only target standards, the lowest-common-denominator of functionality, you will be poorer for it. Linux, for example, has all sorts of performance and functionality enhancing features over what POSIX provides.

Re:Shell Style Guide by Sir_Cmpwn on Tuesday May 15, 2018 @10:05AM (#17073976)
>If you only target standards, the lowest-common-denominator of functionality, you will be poorer for it.

In this case, you won't. I addressed this a few comments ago:

>By the time you need the things bash offers you might as well not use a shell script at all

Re:Shell Style Guide by jhasse on Tuesday May 15, 2018 @11:52AM (#17074882)
> competition between gcc and clang is harmful to the C and C++ ecosystems?

Yes. GCC will die eventually.

Re:Shell Style Guide by nurettin on Tuesday May 15, 2018 @09:25AM (#17073712)
Probably because he can't use bash code in his BusyBox based router
Re:Shell Style Guide by pas on Tuesday May 15, 2018 @11:23AM (#17074608)
And what's the magically amazing script that anyone would like to run on routers and AIXes alike, that it has to be POSIX portable? :)
Re:Shell Style Guide by JepZ on Tuesday May 15, 2018 @09:23AM (#17073695)
Maybe one day there will be another cool and dominating shell. That shell is more likely to be POSIX compliant than bash compliant.
Re:Shell Style Guide by oblio on Tuesday May 15, 2018 @09:32AM (#17073764)
All the cool new shells I've seen are either completely POSIX incompatible (powershell, xonsh, etc.) or they try to be bash supersets (zsh, osh, etc.).

Bash is a de facto modern standard.

The only new purely POSIX shells I know are for embedded stuff (dash) and that space is neither fast moving nor in dire need of a better shell, since most modern shell features target interactive use. Or they make coding easier and/or safer, in which case we're back to point 1, with the POSIX incompatibility.

Re:Shell Style Guide by JepZ on Tuesday May 15, 2018 @12:31PM (#17075197)
Maybe the missing POSIX compatibility is the reason why they haven't replaced bash yet.
Re:Shell Style Guide by oblio on Tuesday May 15, 2018 @03:59PM (#17077320)
Nothing will replace bash within my lifetime. Zsh didn't even though it was superior for over a decade.

Heck, Microsoft barely managed to supplant cmd 1-2 years ago, and that's in a non-standard, proprietary environment by what is arguably the biggest commercial platform maker in the world.

Re:Shell Style Guide by pc86 on Tuesday May 15, 2018 @09:45AM (#17073853)
None of this rant actually says why we should use POSIX shell over anything else though.
Re:Shell Style Guide by wildmusings on Tuesday May 15, 2018 @09:30AM (#17073747)
Portability doesn’t make sense for an operation like Google. Even if some new shell promises compatibility, you still have to test every single script against it. Why bother? Write scripts in bash, run them in bash. In the future, switch to whatever you want for new scripts.
Re:Shell Style Guide by peterwwillis on Tuesday May 15, 2018 @10:57AM (#17074384)
Only if you need portability. If you don't need portability, write it in whatever you want. I prefer bash because it's everywhere. Zsh is too esoteric for me, but I wouldn't judge anyone for using it.
Re:Shell Style Guide by bnferguson on Tuesday May 15, 2018 @09:21AM (#17073676)
You're getting voted down (likely for only saying the article is wrong but not why), but I'm curious your reasoning. I've tended to write in POSIX sh (for maximum compatibility - and because it was just the way I learned) - but am happy to use bash too when the project allows and it makes sense so not sure I get the hard line stance. Wondering what I might be missing to evoke such a response.
Re:Shell Style Guide by Sir_Cmpwn on Tuesday May 15, 2018 @09:26AM (#17073714)
I wrote in some greater detail in response to someone else:

https://news.ycombinator.com/item?id=17073703

Re:Shell Style Guide by raverbashing on Tuesday May 15, 2018 @10:53AM (#17074341)
Nobody cares about non-bash shells if they're not dealing with legacy systems. (And if you are, you have bigger problems)
Re:Shell Style Guide by Sir_Cmpwn on Tuesday May 15, 2018 @10:56AM (#17074371)
Wrong. *BSD are not legacy systems, and many Linux installs don't have Bash. On top of that, new systems can't really implement Bash (because bash is defined by the implementation) but could easily implement POSIX sh (because POSIX sh is defined by the standard).
Re:Shell Style Guide by raverbashing on Tuesday May 15, 2018 @11:44AM (#17074821)
Agreed with BSD, but they usually have bash. (And you usually can compile it for your legacy application - I have done this)

Though I agree that if you're doing something bash specific you're most likely doing something that would be done better using Python/Perl/Ruby, etc

Re:Shell Style Guide by gkya on Tuesday May 15, 2018 @11:19PM (#17079790)
Default *BSD installs do not have bash, it needs to be installed (IDK what DragonFly and TrueOS do, but FreeBSD, NetBSD and OpenBSD don't ship with it). They all have it in the ports trees though. Many distros use BusyBox (IIRC Alpine is one). And AFAIK Debian base only has dash at /bin/sh.

Preferably the complexity in a shell script should be mostly handled by the programs invoked in it. All it has to provide is variables, basic control flow, subshells, and maybe some globbing.

Re:Shell Style Guide by thankthunk on Tuesday May 15, 2018 @09:43AM (#17073839)
> Do not write scripts with bash.

It's a bit too late for that. Bash is pretty much the de facto default shell for linux. Telling people not to use bash scripts is like telling web devs not to use javascript or OS devs not to use C.

It may change in the future, but bash is so entrenched, it's going to take an extraordinary use case for people to move from bash.

Re:Shell Style Guide by orzen on Tuesday May 15, 2018 @10:02AM (#17073960)
Bash is nowhere close for being de facto default shell for Linux. This is a bad analogy. In this case it is more like telling people that want to code Javascript to only write it in React. You got to go from something generic to something specific. Scripts written with bash will often rely on bash-specifics and can therefore only be interpreted by bash. There are entire projects dedicated to stop this plague. If you want to write portable shell scripts, use dash.

https://linux.die.net/man/1/checkbashisms https://mywiki.wooledge.org/Bashism https://wiki.ubuntu.com/DashAsBinSh https://en.wiktionary.org/wiki/bashism

Re:Shell Style Guide by raarts on Tuesday May 15, 2018 @10:52AM (#17074338)
> Bash is nowhere close for being de facto default shell for Linux.

Oh, yes it is. Every important distribution uses bash as the default.

Re:Shell Style Guide by umanwizard on Tuesday May 15, 2018 @11:44AM (#17074827)
Ubuntu has dash as /bin/sh.
Re:Shell Style Guide by jhasse on Tuesday May 15, 2018 @11:54AM (#17074893)
But bash as the login shell.
Re:Shell Style Guide by gkya on Tuesday May 15, 2018 @11:23PM (#17079799)
Login shell means your interactive shell. It does not necessarily mean that that shell should be used for scripting.
Re:Shell Style Guide by JdeBP on Tuesday May 15, 2018 @04:03PM (#17077360)
> It may change in the future, but bash is so entrenched, it's going to take an extraordinary use case for people to move from bash.

You don't know your history. Exactly such a move has already happened once, a decade ago. And it was a success.

* https://lists.debian.org/debian-release/2007/07/msg00027.htm...

* http://initscripts-ng.alioth.debian.org/soc2006-bootsystem/b...

* https://wiki.debian.org/BootProcessSpeedup#Using_a_faster_sy...

Re:Shell Style Guide by moviuro on Tuesday May 15, 2018 @09:51AM (#17073897)
bash is completely out of date on macOS (GPL2 vs. GPL3), and not shipped on any *BSD AFAICT.

Some Linux distro don't ship it either (void, alpine IIRC).

And, most of the time, bash is used because people don't know any better, see e.g. https://github.com/OpenRA/OpenRA/pull/8405/files

Re:Shell Style Guide by falsedan on Tuesday May 15, 2018 @11:00AM (#17074419)
> bash is completely out of date on macOS

I love finding and removing all the GNU/Linux-ism in my bash code when I move it from a dev host to my personal laptop. macOS coreutils don't have GNU longopts, surprise!

Re:Shell Style Guide by umanwizard on Tuesday May 15, 2018 @11:46AM (#17074846)
In case you didn't know: if you really need some GNU tool, you can do `brew install coreutils` (assuming you use Homebrew).

The installed binaries will have their names prefixed with `g`; e.g. `gdate` instead of `date`.

If something you want isn't part of coreutils, you can often install it directly; e.g. `brew install gawk` or the weirdly-named `brew install gnu-sed` (which names its installed binary `gsed`... go figure.)

Re:Shell Style Guide by falsedan on Tuesday May 15, 2018 @06:44PM (#17078566)
I know this; but can I teach every potential user of my scripts this same fact through documentation I have to maintain? What if: I write the code so that documenting it is easier?
Re:Shell Style Guide by gkya on Tuesday May 15, 2018 @11:24PM (#17079802)
Quite some people use Zsh interactively.
Re:Shell Style Guide by Sir_Cmpwn on Tuesday May 15, 2018 @09:49AM (#17073881)
>Telling people not to use bash scripts is like telling web devs not to use javascript or OS devs not to use C.

Wow, this comparison is totally whack. Javascript and C are both standardized and the former is the only option when using a web browser.

It's never too late. We managed to get people off of ANSI C and there's a similar amount of difference between ANSI* C and C89 as there is between bash and sh.

* correction: pre-ANSI

[dead]
Re:Shell Style Guide by Sir_Cmpwn on Tuesday May 15, 2018 @10:17AM (#17074055)
>Javascript isn't the only option. It is the most popular by far and hence the "de facto" language of the web. And javascript certainly isn't "standardized" in the sense you are writing. Do you know anything about web development, browser implementation of javascript and javascript itself? Javascript is no more "standardized" than SQL is standardized. Every RDBMs implements their own flavor of SQL just like browsers do with javascript.

This is nonsense. I am very familiar with web browsers. Javascript is standardized as ECMAScript:

https://www.ecma-international.org/publications/standards/Ec...

The "standard library" browsers implement is also standardized:

https://www.w3.org/standards/

You're off your rocker.

>Did I say it was too late? Of course I didn't. Maybe if you took a step back from your fanboyism and read...

Here is a direct quote from your comment:

>It's a bit too late for that. Bash is pretty much the de facto default shell for linux.

>ANSI C and C89 are the same thing. ANSI C is just another name for C89... Sigh...

Derp, I meant K&R C or pre-ANSI C. My mistake.

Re:Shell Style Guide by dang on Tuesday May 15, 2018 @12:33PM (#17075212)
> This is nonsense [...] You're off your rocker.

Come on Drew, you know better than to do this here, regardless of how wrong someone is. If senior users set this kind of example how can we tell new ones not to?

https://news.ycombinator.com/newsguidelines.html

Re:Shell Style Guide by Sir_Cmpwn on Tuesday May 15, 2018 @01:06PM (#17075518)
You're right, I'm sorry.
Re:Shell Style Guide by thrwwy12345 on Wednesday May 16, 2018 @10:42AM (#17082768)
> Come on Drew, you know better than to do this here, regardless of how wrong someone is.

But I wasn't wrong. I was right. But you wouldn't know that because your a gender studies major and not a CS major.

> If senior users set this kind of example how can we tell new ones not to?

And yet no flagging and no ban. How hypocritical of you. The guy instigated it and yet you banned the victim rather than the victimizer. Also senior? I've been using hacker news since the very beginning. Long before trash like you arrived daniel.

Re:Shell Style Guide by dang on Wednesday May 16, 2018 @01:57PM (#17084743)
"Regardless of how wrong someone is" does not imply that anyone was wrong. It just says that even if they're wrong, other users must remain civil. That's why we use that wording.
[dead]
Re:Shell Style Guide by dang on Tuesday May 15, 2018 @12:35PM (#17075220)
We've banned this account for repeatedly breaking the site guidelines. Would you please not create accounts to do that with?

If you don't want to be banned, you're welcome to email [email protected] and give us reason to believe that you'll follow the rules in the future.

https://news.ycombinator.com/newsguidelines.html

Re:Shell Style Guide by thrwwy12345 on Wednesday May 16, 2018 @10:43AM (#17082781)
A quick question. How proud are your parents that you moderate comments on a silly forum? Do they brag about your "career" during family gatherings on thanksgiving? Do you ever wake up and realize that you moderate comments for a living and get depressed/suicidal? Can you think of a more worthless existence that moderating comments? I commend you for not jumping in front of a train or jumping off a bridge. It takes real fortitude for someone so useless to keep going.
Re:Shell Style Guide by anothergoogler on Tuesday May 15, 2018 @09:57AM (#17073928)
Truly portable shell scripts cannot define functions. Have you ever seen autotools' output? No thanks, I'll be impure and wrong and get the job done. Also your comment is off-topic... not sure why you see every thread about Bash as the right place to start this pedantic flameskirmish.
Re:Shell Style Guide by Sir_Cmpwn on Tuesday May 15, 2018 @10:02AM (#17073959)
Of course portable shell scripts can define functions. What are you talking about? Shell functions are defined in POSIX. Maybe you should consult the standard before you proceed:

http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3...

Re:Shell Style Guide by anothergoogler on Tuesday May 15, 2018 @10:06AM (#17073992)
I'm technically wrong per POSIX but practically right per your principle motivation of portability: https://www.gnu.org/software/autoconf/manual/autoconf-2.66/h...

> Unfortunately, even in 2008, where shells without any function support are far and few between, there are pitfalls to avoid when making use of them. Also, finding a Bourne shell that accepts shell functions is not trivial, even though there is almost always one on interesting porting targets.

Re:Shell Style Guide by Sir_Cmpwn on Tuesday May 15, 2018 @10:15AM (#17074046)
This document is 10 years old, and even then it acknowledged that finding shells without function support is a tough ask. You're not practically right, either.

When a system does not (correctly) implement portable standards, it is a bug in the system and software should not be corrected to accomodate for it. autotools disagrees with me on this point.

Re:Shell Style Guide by anothergoogler on Tuesday May 15, 2018 @10:24AM (#17074096)
Yea, I'm going to side with autotools' maintainers on matters of software portability. And because I'm not aiming for autotools-levels of portability, I just write v3-compatible Bash, to help out my GPL2 OSX friends.
Re:Shell Style Guide by fipar on Tuesday May 15, 2018 @10:20AM (#17074079)
I don't see how the comment is off-topic. While the HN title is "Google's bash style guide", the actual guide has the title "Shell Style Guide". To some, that reads as if a "Programming Style Guide" started by saying only C is allowed.