help-bash
[Top][All Lists]
Advanced

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

printf '%s\n' "$@" versus <<< redirection


From: goncholden
Subject: printf '%s\n' "$@" versus <<< redirection
Date: Sat, 18 Feb 2023 08:50:02 +0000

I am using the following bash function 

theone ()
 {
  printf '%s\n' "$@"  \
    | while IFS="" read -r vl; do
      ...
      done
 }

I have also been looking at this second implementation

theone ()
 {
   while IFS="" read -r vl; do
      ...
   done <<< "$@"
 }

But it occurs to me that the two are actually different.  Using <<< means 
reading from stdin, 
which will not preserve the arguments, so special chars (like newline) may 
cause troubles. 

The first implementation honours newlines in the arguments, whilst also 
introduces a newline
between arguments (between $1, $2, $3, etc).  Am I missing anything in my 
analysis ?




reply via email to

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