[LinuxSIG] ChatGPT to write code [was: Re: bash_httpd.sh]

Ron / BCLUG admin at bclug.ca
Sun Mar 3 12:38:41 PST 2024


Dave Hylands wrote on 2024-03-03 07:33:

> There are still some things I prefer to use bash for rather than Python 
> (usually involving transforming the output of a program). But yeah it’s 
> amazing what you can do with a well crafted bash script.

Indeed. It's powerful, if also rather painful.


> I tend to use trap a lot more in scripts that get used in a more 
> production environment.

Yeah, ditto.  Even then, I usually fail to add them.



> I’ve also found myself putting the incantation:
> 
> `set -Eeuo pipefail`
> 
> at the top of all my bash scripts.
> 
> This page gives an detailed explanation of most of what that means:
> https://gist.github.com/mohanpedala/1e2ff5661761d3abd0385e8223e16425?permalink_comment_id=3935570


Great resource!

Following the link to the original version is worthwhile too.

I think I'll remember it better after that summary.

(I think I've said similar before though.)



> The -E makes trap statements get inherited by shell functions.

Handy!



I'm reminded of a neat utility Nick Holland demonstrated at an online 
presentation a while back: Try, Cry, Die (he calls it Try, Yell, Die):


## Nick Holland SemiBUG lecture:
## https://egoslike.us/semibug/shellscriptingtips2.html
##
## http://www.mpaoli.net/~michael/unix/sh/

yell() { echo "$0: $*" >&2; }
die() { yell "$*" ; kill -s SIGINT $$; }    ## exit 111; }
try() { "$@" || die "cannot $*" ; }



Thanks for the `set` reminder Dave!

rb






More information about the LinuxSIG mailing list