|
|
Subscribe / Log in / New account

Python as a shell replacement

Python as a shell replacement

Posted Dec 13, 2019 22:59 UTC (Fri) by marcH (subscriber, #57642)
In reply to: Python as a shell replacement by BenHutchings
Parent article: Creating Kubernetes distributions

Yes, set -e is absolutely not a silver bullet. It does not catch all errors, so you must lower your expectations. It does catch many of them, which has saved me and many others a lot of time, routinely, for years.

Some influent and vocal experts seem to have decided that, short of catching "all errors", catching "no error" is better than "many errors". I've read all their essays and I still couldn't make sense of their logic https://mywiki.wooledge.org/BashFAQ/105

"Works for us".

PS: besides 105 and a couple others, https://mywiki.wooledge.org/BashFAQ is the best.


to post comments

Python as a shell replacement

Posted Dec 14, 2019 0:08 UTC (Sat) by karkhaz (subscriber, #99844) [Link]

I occasionally use a combined shell script/makefile if I care about catching errors on each command:

#!/bin/sh
# vim:set syntax=make:set ft=make:

MAKEFILE_START_LINE=$(\
  grep -nre makefile_starts_here "$0" \
  | tail -n 1 \
  | awk -F: '{print $1}')

TMP=$(mktemp)
tail -n+${MAKEFILE_START_LINE} "$0" > "${TMP}"

make -f "${TMP}"
SUCCESS=$?

rm -f "$TMP"
exit "$SUCCESS"

makefile_starts_here:
	command-1
	command-2
	command-3

This prints out everything below and including "makefile_starts_here" to a Makefile and then runs make on it, executing the commands one at a time. This is especially nice if I want built-in parallelism etc, it's actually even better than just using the shell (just ensure to print out "MAKEFLAGS=-j" at the top of the file).


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds