help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

printf $variable inside initial parenthesis or use %s?


From: Roger
Subject: printf $variable inside initial parenthesis or use %s?
Date: Wed, 11 Jan 2023 02:59:52 -0500

When using builtin bash printf, which is more appropriate?

printf "$var"

or

printf "%s" $var

(Disregarding proper variable quoting syntax for ensuring proper variable 
expansion.)

My guess, since Bash builtin printf was designed for a drop-in POSIX 
replacement for echo, keep it simple and likely just use the first incantation, 
printf "$var".  While using %s only when fancier printing is required.

I noticed while using the printf %s incantation, I typed double the amount of 
quotes for ensuring proper variable expansion, while also additionally having 
to keep track of the number of %s matched the number of variables to print.  So 
the effort for typing the %s syntax seems more time consuming and is likely 
more prone to typing mistakes.

Roger




reply via email to

[Prev in Thread] Current Thread [Next in Thread]