Pass variable from awk to bash
5,179
Assuming you trust the incoming data that awk is processing.
You can have awk print out shell variable declarations, and source
the output of awk like it's a shell file:
source <(
awk '
# ....
print "var1=" value1
print "var2=" value2
# ....
' input
)
echo "shell var1 = $var1"
echo "shell var2 = $var2"
Related videos on Youtube
Author by
diego9403
Updated on September 18, 2022Comments
-
diego9403 3 months
How can I pass variable from awk to bash? I want to pass a lot of variable, so I don't use:
x=$(awk '.....)
I thing it's not usefull.
-
diego9403 over 7 yearsIt's very strange for me, but it's works. Do you know other way?
-
rici over 7 years...and assuming the values have no whitespace or metacharacters in them.
-
glenn jackman over 7 years@diego9403, another way would be to not use awk and do whatever you're doing with bash instead.