[u-u] Sams book

Jim Mercer jim at reptiles.org
Fri Jan 15 15:07:47 EST 2016


On Fri, Jan 15, 2016 at 02:58:20PM -0500, D. Hugh Redelmeier wrote:
> | From: Vance Shipley <vances at motivity.ca>
> 
> | On Fri, Jan 15, 2016 at 9:08 PM, Jim Mercer <jim at reptiles.org> wrote:
> | > if your shell scripting depends on new features, you are doing it wrong.
> 
> Mostly I agree.
> 
> There's a pair of bash features I try to recommend to everyone for
> most scripts:
> 
> 	set -eu
> 
> The -e means "stop on error returns".  This is very good at exposing
> problems that are otherwise silent.

-e completely changes the way the shell runs, and i highly suggest never
enabling it.

for example, if you have anything like

#! /bin/sh

someprog -a -b -c
if [ $? -ne 0 ] ; then
   take some action
fi

it totally will not do what you think.

i lost a chunk of hair trying to figure out why a script were failing
silently, then discovered that someone had put in "#! /bin/bash -e"

also, if you are writing a bash script, start with #! /bin/bash,
even if your system errantly installs bash as /bin/sh

bash != bourne shell

--jim

> The -u means that a reference to an undefined variable is an error.
> So misspellings don't slip through.
> 
> Using -e isn't fun for an interactive shell!
> 
> | As a rue of thumb I would agree.
> 
> I love that (Freudian?) slip.  I often rue what my thumb types.
> 
> _______________________________________________
> u-u mailing list
> u-u at unixunanimous.org
> https://unixunanimous.org/mailman/listinfo/u-u

-- 
Jim Mercer     Reptilian Research      jim at reptiles.org    +1 416 410-5633

Life should not be a journey to the grave with the intention of
arriving safely in a pretty and well preserved body, but rather
to skid in broadside in a cloud of smoke, thoroughly used up,
totally worn out, and loudly proclaiming "Wow! What a Ride!"
 -- Hunter S. Thompson


More information about the u-u mailing list