How would you suggest to consecutively assign one variable per word of string?I am looking for the short command: one-liner and without loop if possible. It should have of the formecho <sring>  | your_commandExample:The string is word1 word2 word3I want to assign the variable w1 to word1, w2 to word2 and w3 to word3.
How to assign one variable per word of a string
bash;shell script;awk;gawk
This works in ksh93 but not in bash since bash runs the read in a sub-shell:echo word1 word2 word3 | read w1 w2 w3printf '%s\n' $w1 $w2 $w3This means that you simply can't have an assignment as part of a pipeline in bash.The workaround is to use the variables before the pipeline sub-shell exits:echo word1 word2 word3 | { read w1 w2 w3 && printf '%s\n' $w1 $w2 $w3; }or,echo word1 word2 word3 | {  read w1 w2 w3  printf '%s\n' $w1 $w2 $w3}This works in both shells:read w1 w2 w3 <<<word1 word2 word3printf '%s\n' $w1 $w2 $w3