Question

#!/bin/bash 
command1 |while read
do
set -- $REPLY
command2
done

I was browsing the net and I came across this piece of code. What does 'set -- $REPLY' do ?

Was it helpful?

Solution

It splits down $REPLY into tokens and put them into $@ (arguments)

$REPLY is the implicit target for while read expression. But do remember that using while read with implicit target is a bash-ism and it's supported in e.g. ash (but supported in zsh). Better use while read REPLY

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top