I would like to create a single sentence (In order partially answer my question: AWK Assignment and execute operation with variables, using split and concatenation without space).
% awk 'BEGIN { str1 = "foo"; str2 = "bar"; str3 = str1 str2; print str3 }'
foobar
That is very easy. But, before is static!!!
Taking in account:
% echo $(echo "foo")
foo
Now, I would like to "calculate" the value of str1.
% awk 'BEGIN { str1 = $(echo "foo"); str2 = "bar"; str3 = str1 str2; print str3 }'
awk: illegal field $(foo), name "(null)"
source line number 1
Is it possible to do the assignment dynamically (product of other action/command) the value for str1 using AWK?
As @anubhava help me:
I get:
% awk -v str1="$(echo "foo")" 'BEGIN {str2 = "bar"; print str1 str2 }'
foobar
Now, How I can use the first variable as argument for assignment for second variable?
% awk -v str1="$(echo "foo")" -v str2="$(echo str1)bar" 'BEGIN {my operation with str2 }'
But Currently I get:
% awk -v str1="$(echo "foo")" -v str2="$(echo str1)bar" 'BEGIN {print str2 }'
str1bar
Partially:
% str1="$(echo 'foo')"; str2="$(echo ${str1}'bar')";awk -v result="$str2" 'BEGIN{print result}'
foobar