[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: printf $variable inside initial parenthesis or use %s?
From: |
Greg Wooledge |
Subject: |
Re: printf $variable inside initial parenthesis or use %s? |
Date: |
Thu, 12 Jan 2023 17:16:22 -0500 |
On Thu, Jan 12, 2023 at 05:06:02PM -0500, Roger wrote:
> Another idea, initially write scripts using echo, then later re-code/fix and
> use printf.
>
> This will save a lot of typing time, with echo/printf statements being added
> and removed during development (although I usually leave most echo/printf
> statements for later debugging), that do not remain in the final end product
> or
> working script. Like I previously stated, printf %s syntax format tends to
> double typing time. Albeit, using this tactic, most will just forget and
> keep
> the echo statements!
If you wish to continue using echo for convenience/brevity, you can
drop a function like this into your script:
echo() { local IFS=' '; printf '%s\n' "$*"; }
That will make echo behave the way most people want/expect it to:
print each argument verbatim, with spaces between them if there's
more than one, and then print a newline at the end.
Re: printf $variable inside initial parenthesis or use %s?, David, 2023/01/11