the padded cell

#shell-scripting

20 August, 2025

gum simplifies making shell scripts interactive: no more wrestling with read commands and ANSI escape codes for user input: just proper text editing, defaults, and clean UI.

Their demo: gum gemo

For example, if you run:

gum input --width 50 --header "Favorite author?" \
 --value "Terry Pratchett"

It will give you a question with a sensible default that you can then change as you want, and what you wrote as you hit enter will be returned so your script can then use it.

If you instead has some options where you want to select one:

gum choose --header "Favorite book?" \
 "Hogfather" "Thief of Time" "The Night Watch" "Small Gods"

Which gives you a selection box, you can configure to allow multiple selections, and the one you pick is then returned.

And one I really love, have it show a spinner to indicate that yes… something is still going on:

gum spin --title="Counting down from 10" sleep 10

Built on bubbletea, a Go TUI framework, use that directly if you need these components in Go code rather than shell scripts.

15 August, 2025

If you start a non-interactive bash shell it will source the content of the file defined in BASH_ENV (and ENV for a POSIX shell).

When bash is started non-interactively, to run a shell script, for example, it looks for the variable BASH_ENV in the environment, expands its value if it appears there, and uses the expanded value as the name of a file to read and execute. Bash behaves as if the following command were executed:

if [ -n "$BASH_ENV" ]; then . "$BASH_ENV"; fi

but the value of the PATH variable is not used to search for the file name.

13 August, 2025

/usr/bin/env executes commands with flags/subcommands, not just bare executables. Which is great if you, for example, have a script/lint that’s a Python script, and it needs dependencies from a virtualenv that isn’t active when you call it.

Just put your shebang as /usr/bin/env uv run python3 and it always runs in the virtualenv, no wrapper script needed. This feels obvious in hindsight, it’s what you expect from these tools 😃

02 August, 2025

In shell scripts if you do "$@" it will actually expand “quoted sentences” correctly, and if you just do $@ it will always unwrap them into single words, I thought that if you did "$@" it would combine all arguments into a single argument, and what it does is do what I thought $@ alone did.

I.e., with "$@" the arguments "one two" three will be 2 arguments, the first being "one two", and without it will become three arguments, all separated by space.

The scripts/commands inside a shell script inherit access to STDIN when you call them, so if you have a shells script that only has cat and you do ./script.sh < script.sh then it’ll output the content of itself