Today, writing scripts, encountering awk script to the shell of the case, the internet Google, found that there are some problems, through the pipeline, through Eval, feeling is very complex. So I thought to try it with read.
First, a test file Test.txt is constructed, and the contents are 1 2 3.
First try
' {print $ $} ' test.txt | Read a b C
But echo $a, found to be empty, failed.
Try it.
" 1 2 3 " | Read a b C
You can't assign a b c to a value.
It seems that read is not the use of, angry Google, in StackOverflow found a similar problem (StackOverflow true artifact Ah! )
Links: http://stackoverflow.com/questions/374687/why-is-echo-foo-read-a-echo-a-not-working-as-expected
There was a reply from the Lord mentioning that
Read a < < (echo foo)
You can assign a value to a, try it, sure enough.
And then try
Read a B c< < (echo foo goo hoo)
You can also assign a B c to a value separately! It's so exciting!
Then try
' {print $ $} ' test.txt)
Failed, the value of a becomes 123,b,c empty.
Why is this? Because awk does not print a space, it only prints 123, which of course is assigned to a.
So, add separators
' {print $ "" $ "" $ $} " ' test.txt)
It's a success!
Considering my awk is going to be a little more complicated.
1 ' {test=$1;test2=$2;test3=$3}end{print Test,test2,test3} ')
And it worked!
Thus, awk can pass values to the shell in such a way.
How awk passes a value to the shell