Just discovered two useful features commonly available in shells:
1. printf "%q" 'thing!'
The %q sequence in the printf commands transforms an argument in a quoted version (see screenshot)
2. disown
This one is a builtin in bash and zsh, but not in dash. It disowns the last background job and, with that, closing the shell won't kill the disowned job. I'm using this for an opener script.

(I know printf isn't a shell builtin, but it is available in most systems, I guess)

@yohanandiamond

1. %q is GNU- and zsh-specific

It's in GNU /usr/bin/printf and bash/zsh builtins, but busybox printf and dash's builtin error out and it's not in the FreeBSD, OpenBSD, NetBSD, DragonFly BSD, macOS, or Solaris printf manpages.

2. printf(1) isn't just "available in most systems", POSIX requires it:

pubs.opengroup.org/onlinepubs/

3. printf actually is a builtin under busybox, dash, bash, and zsh… but only zsh makes `which` a builtin:

% which printf
printf: shell built-in command

Follow

@yohanandiamond I found a long Unix & Linux Stack Exchange answer which explains what a mess things are with echo and extensions to printf and why it's generally a good idea to stick to the POSIX-specifed subset of printf:

unix.stackexchange.com/a/65819

@ssokolow Thanks for the clarification, this answers pretty much every question I had related to the topic :P

Sign in to participate in the conversation
Qoto Mastodon

QOTO: Question Others to Teach Ourselves
An inclusive, Academic Freedom, instance
All cultures welcome.
Hate speech and harassment strictly forbidden.