people always forget about the humble printf in shell
for example, imagine you want to some operation like sort uniq over space separated values in a string (traditional way to do arrays besides set —): instead of echo into IFS mangling etc consider:
printf ‘%s\n’ $VARS | …
want = pairs? printf ‘%s=%s\n’
and so on

@toast it’s cool but has a bunch of pitfalls if you’re not careful

i.e. people using printf and letting the format-string be user controlled

thankfully -v can only be the first argument, so you can’t accidentally let an attacker write to an arbitrary variable… rare case when the posix parameter order actually helps

(do note: i’m in the 0.1% of shell scripters who even consider it to be a “security boundary” of any sort because of httpsh, so i’m firmly an outlier and i shoudl not have been counted)

@domi @toast i got so confused for a while, checked the posix and coreutils manpage, got even more confused

then checked the bash manpage, and then it made sense

now i wonder why did bash add printf -v var when we had var=$(printf) =w= maybe some edge case i can’t think of

@navi @domi @toast

$() strips trailing newlines. It would need to be var=$(printf 'foo\nx'); var=${var%x}