Reputation: 17
How to print output from a loop which is piped to some other command:
for f in "${!myList[@]}"; do
echo $f > /dev/stdout # echoed to stdout, how to?
unzip -qqc $f # piped to awk script
done | awk -f script.awk
Upvotes: 0
Views: 36
Reputation: 141768
You can use /dev/stderr
or second file descriptor:
echo something >&2 | grep nothing
echo something >/dev/stderr | grep nothing
You can use another file descriptor that will be connected to stdout:
# for a single command group
{ echo something >&3 | grep nothing; } 3>&1
# or for everywhere
exec 3>&1
echo something >&3 | grep nothing
# same as above with named file descriptor
exec {LOG}>&1
echo 123 >&$LOG | grep nothing
You can also redirect the output to current controlling terminal /dev/tty
(if there is one):
echo something >/dev/tty | grep nothing
Upvotes: 3