Live data from Hacker News

Common shell script mistakes (2008)

pixelbeat.org

61–70 of 82 posts

Re: Common shell script mistakes (2008)

#61
post #26

Earlier quoted context omitted.

>3) Multiprocessing IMO shell makes it very easy to work with multiple process (&). It's built in and natural. >4) Performance If you are carefull and know what you're doing, you can achive very good performance with the shell. Usually, better performance is achived processing less data, ie being inteligent. Rarely depends on the language (unless you care about cycle level performance, then yes :). >6) Portability I…

With regards (3), my problem in shell is that it is very hard to spawn children without risking overloading the machine. What I would like in bash is some easy way to limit the number of background processes I can spawn, and to just wait when I try to start another one until an existing one is finished. Some simple jobs can be converted to use xargs -P, but for more complex things I end up having to do them without p…

Yes ... I think that should not be allowed (bring down the machine by a non-root user process). In Linux CPU_GROUPS/MEM_GROUPS can help, and the fair scheduler has improved the situation a bit from the old days where a fork bomb will bring the machine down.

But limiting the # of spawned children is possible using not so complicated ad-hoc solutions, but I guess it depends on the specific problem.

Re: Common shell script mistakes (2008)

#62
post #43
post #33

Earlier quoted context omitted.

The google shell style uses bash which is not portable, one of the main point of the OP article.

Bash is the default shell on the most popular server nix (Linux) and the most desktop nix (OS X, though it's always a slightly old version). If you use OpenBSD and hate ports, then maybe ignore all the good things bash brings and write everything in Bourne shell. If not, then write bash. Just fire it up with '/usr/bin/env bash' to label it correctly.

"OS X, though it's always a slightly old version"

Apple ships the last version that had a GPL2 license. That version gets older by a day every day.

On OS X 10.11.2, it seems to be bash 3.2 (http://opensource.apple.com/source/bash/bash-99/, via http://opensource.apple.com/release/os-x-10112/), which is from October 12, 2006 (https://lists.gnu.org/archive/html/info-gnu/2006-10/msg00006...)

I wouldn't call that slightly old.

Re: Common shell script mistakes (2008)

#63
post #42

Earlier quoted context omitted.

But once you adopt bash-only features, you're losing the main argument for a shell script: portable scripting without the need to first install something to get something else running. Once you require Bash, it's equally easy to demand Perl and that will provide a much richer scripting experience.

When it this last time you logged into a box and /bin/bash wasn't an option? Let me guess 1999 on a SPARC box running Sun Solaris?

today. the various BSD systems all come without bash in their default configurations (and it's never in /bin).

this should not be construed as an argument in support of /bin/sh.

Re: Common shell script mistakes (2008)

#64
post #43
post #33

Earlier quoted context omitted.

The google shell style uses bash which is not portable, one of the main point of the OP article.

Bash is the default shell on the most popular server nix (Linux) and the most desktop nix (OS X, though it's always a slightly old version). If you use OpenBSD and hate ports, then maybe ignore all the good things bash brings and write everything in Bourne shell. If not, then write bash. Just fire it up with '/usr/bin/env bash' to label it correctly.

> Bash is the default shell

Not for nigh on a decade, now.

* https://wiki.ubuntu.com/DashAsBinSh

* https://wiki.ubuntu.com/DashAsBinSh/Spec

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

* https://wiki.debian.org/DashAsBinSh

Re: Common shell script mistakes (2008)

#65

Earlier quoted context omitted.

When it this last time you logged into a box and /bin/bash wasn't an option? Let me guess 1999 on a SPARC box running Sun Solaris?

Do embedded systems count? ;)

I'm having trouble remembering the last time I saw a BSD box during my work day, unless Juniper gear counts. No knock against BSD but seriously how many people are writing POSIX shell scripts because they need their shell scripts to work with Linux, QNX and BSD?

Re: Common shell script mistakes (2008)

#66

Earlier quoted context omitted.

Do embedded systems count? ;)

I'm having trouble remembering the last time I saw a BSD box during my work day, unless Juniper gear counts. No knock against BSD but seriously how many people are writing POSIX shell scripts because they need their shell scripts to work with Linux, QNX and BSD?

You should be first asking how many people are writing POSIX shell scripts because they need their shell scripts to work with Debian and Ubuntu.

* http://unix.stackexchange.com/a/250965/5132

* https://debian.org/doc/debian-policy/ch-files.html#s-scripts

* http://manpages.ubuntu.com/manpages/xenial/en/man1/checkbash...

* http://manpages.ubuntu.com/manpages/xenial/en/man1/posh.1.ht...

The answer is, of course, lots of them; as there was a massive project to do exactly this in Debian and Ubuntu some years ago.

Re: Common shell script mistakes (2008)

#67
post #42

Earlier quoted context omitted.

But once you adopt bash-only features, you're losing the main argument for a shell script: portable scripting without the need to first install something to get something else running. Once you require Bash, it's equally easy to demand Perl and that will provide a much richer scripting experience.

When it this last time you logged into a box and /bin/bash wasn't an option? Let me guess 1999 on a SPARC box running Sun Solaris?

> When it this last time you logged into a box and /bin/bash wasn't an option?

A few hours ago; and before that, last Wednesday. The latter says:

    JdeBP % /bin/bash
    zsh: no such file or directory: /bin/bash
    JdeBP %
The Z Shell is an add-on here, too. /bin/sh is the Korn shell. No, it's not OpenBSD.

Re: Common shell script mistakes (2008)

#68
post #57

Earlier quoted context omitted.

> If that's the only criterion, then the parent just followed the logic. wodenokoto offered up some reductio ad absurdum and you are calling it logic. It was not the only criterion. It was the only criterion that was explicit. There are implied criterion and most of us understand what pwd_mkdb means even if we don't necessarily agree with him.

> It was the only criterion that was explicit. Well, even in itself, it is wrong. It's not just that other criteria apply too -- it's that it alone needs several caveats, as succinctness is quite orthogonal to readability (e.g. sometimes even needless boilerplate syntax that the compiler could infer by itself, make for better readability when present).

> Well, even in itself, it is wrong.

I am not in disagreement with you about whether it is wrong, I am in disagreement with you about why it is wrong.

The counter argument was that Y is wrong and X is Y, therefore X is wrong. While this is a valid argument, it is not sound, because X is not Y.

> ... succinctness is quite orthogonal to readability ...

There is a relationship between succinctness and readability. The relationship is definitely not directly proportional as the pwd_mkdb's post could be read to imply, but to say there is no relationship between the two is flatly absurd.

Re: Common shell script mistakes (2008)

#69
post #64
post #43

Earlier quoted context omitted.

Bash is the default shell on the most popular server nix (Linux) and the most desktop nix (OS X, though it's always a slightly old version). If you use OpenBSD and hate ports, then maybe ignore all the good things bash brings and write everything in Bourne shell. If not, then write bash. Just fire it up with '/usr/bin/env bash' to label it correctly.

> Bash is the default shell Not for nigh on a decade, now. * https://wiki.ubuntu.com/DashAsBinSh * https://wiki.ubuntu.com/DashAsBinSh/Spec * https://lists.debian.org/debian-release/2007/07/msg00027.htm... * https://wiki.debian.org/DashAsBinSh

Bourne shell being replaced as /bin/sh by dash doesn't change anything: Linux and OSX don't use /bin/sh as the default shell.

Re: Common shell script mistakes (2008)

#70
post #69
post #64

Earlier quoted context omitted.

> Bash is the default shell Not for nigh on a decade, now. * https://wiki.ubuntu.com/DashAsBinSh * https://wiki.ubuntu.com/DashAsBinSh/Spec * https://lists.debian.org/debian-release/2007/07/msg00027.htm... * https://wiki.debian.org/DashAsBinSh

Bourne shell being replaced as /bin/sh by dash doesn't change anything: Linux and OSX don't use /bin/sh as the default shell.

> Linux and OSX don't use /bin/sh as the default shell.

You didn't even read the first sentence of the first hyperlinked page.

Post reply on HN