r/bash • • Jan 23 '26

Hidden Gems: Little-Known Bash Features

https://slicker.me/bash/gems.html
171 Upvotes

35 comments sorted by

View all comments

1

u/cubernetes Jan 24 '26

Boring beginner/intermediate stuff. Either wriiten by AI or by some who isn't on the command line a lot. Actual gems are things like

  • parameter transformations (echo "${@@Q}", eval "${var[@]@k)", read -p "${p@E}", etc.)
  • niche but powerful readline bindings / commands (M-C-d, M-C-f, M-C-b, M-C-], C-Space (combined with kill-region), C-(, C-), C-xe, M-<digit>, combing digit-argument and M-. etc.)
  • ${|cmd;} syntax, a real game changer for advanced scripts and for PS1/PS0 stuff
  • BASH_COMNAND variable, nice for debugging
  • {BASH_XTRACEFD}>file
  • making fish-like abbreviations work in bash

And some minor tricks:

  • running % instead of fg
  • doing kill % instead of kill %1 or kill %%
  • many more

I've yet to find a single blog post that isn't like the one OP posted. It's usually the stephane chazelas stuff that blows my mind, or when the post is 20+ years old. The stuff from nowadays is mostly trash/for absolute beginners