Is there a way to set a variable in my current shell from within awk
?
I\'d like to do some processing on a file and print out some data; since I\'ll rea
To synthesize everything here so far I'll share what I find is useful to set a shell environment variable from a script that reads a one-line file using awk. Obviously a /pattern/
could be used instead of NR==1
to find the needed variable.
# export a variable from a script (such as in a .dotfile)
declare $( awk 'NR==1 {tmp=$1} END {print "SHELL_VAR=" tmp}' /path/to/file )
export SHELL_VAR
This will avoid a massive output of variables if a declare
command is issued with no argument, as well as the security risks of a blind eval
.