Re:Shell Style Guide
by peterwwillis on Tuesday May 15, 2018 @10:55AM
(#17074366)
/bin/sh is most often either the C shell, Dash, or Ash, not the Bourne shell. Bourne shell extensions will cause the script to fail.
edit: bourne again shell
You certainly meant /bin/sh is not the Bourne again shell. I updated my comment to clear any possible misunderstanding
/bin/sh shouldn't be a C shell, it's always a POSIX-compatible shell IIRC
In the wild, hopefully not, but I do remember coming across /bin/sh executing csh in an obscure RTOS-ish / proprietary flavor of Linux that we were prototyping at a previous employer. Would've been around 2008. I can't remember the variant, but I remember being caught off-guard by it.
AFAIK /bin/sh is standard; if you cannot trust that /bin/sh is a Bourne-like sh, you might as well have to assume /usr/bin/env can not be what it was meant to be too.
Re:Shell Style Guide
by peterwwillis on Tuesday May 15, 2018 @12:14PM
(#17075058)
I suppose you're right, though the main point is it may not have Bourne-again extensions
I once triggered an automatic deploy that ran a bash script that minified a bunch of css/html/js assets and pushed them to S3, at some path like `/assets/vX.X.X/whatever.css`. Unfortunately, a few of our deploy boxes had Dash instead of Bourne shell, and when it ran on dash it failed to parse the version tag to push and ended up pushing an empty dir to /assets - deleting everything. Fun experience.
Re:Shell Style Guide
by michaelcampbell on Wednesday May 16, 2018 @02:26PM
(#17085070)
> /bin/sh is most often either the C shell,
Never once have I ever seen this. In 25+ years.
Doesn't explain why Google wouldn't use env unless there's a good reason to avoid env.
Top of my head:
- it works
- it's simple
- they know that bash is in /bin
- maybe it avoids a needless call to env, resulting in better startup time (see e.g. https://news.ycombinator.com/item?id=16978932 for a similar situation with python)
People who share code for the world to use should use:
- `#!/usr/bin/env bash`
- or `#!/bin/sh` for POSIX shell scripting