[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: printf $variable inside initial parenthesis or use %s?
From: |
alex xmb ratchev |
Subject: |
Re: printf $variable inside initial parenthesis or use %s? |
Date: |
Wed, 11 Jan 2023 09:17:24 +0100 |
its %s to data one-to-one
excepts u got $var2 or so which contains %'s es to be used
cause .. else %'s and \'s get interpreted
for this bash has %b , to interpret \'s in its data arg
%q for shell-quoted
On Wed, Jan 11, 2023, 09:00 Roger <rogerx.oss@gmail.com> wrote:
> 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
>
>
>
Re: printf $variable inside initial parenthesis or use %s?, David, 2023/01/11