سؤال

#!/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 ?

هل كانت مفيدة؟

المحلول

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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top