Sun, 19 Aug 2012 17:51:34 -0700, happytoday did cat :
> How can under batch file to store value for returning value from awk
> program ?
for a direct answer to your direct question use Ed.'s answer
for an indirect answer to your hidden probable question I'd say
first use a file then use source on it
a little PoC goes a long way cause it's hot:
your given env var:
-------------
$ export _BARF=888
-------------
the PoC script:
-------------
$ cat bhappy.sh
#!/bin/bash
### call thrice an awk script that might have a try at
### incrementing an environment variable
### this is the given env variable to play with
echo "Before anything goes: $_BARF"
_BARF=999
export _BARF
echo "Right after first fighting: $_BARF"
###
### this is the simple mind awk to do just what to do
###
cat<<EOF>bhappy.awk
BEGIN{
x=ENVIRON["_BARF"]
x+=101
ENVIRON["_BARF"]=x
printf("\n\tin awk, x=%s, envB=%s.\n",x,ENVIRON["_BARF"])
}
EOF
###
cat<<EOT>bhappy2.awk
BEGIN{
x=ENVIRON["_BARF"]
x+=101
printf("export _BARF=%s\n",x) > _fout_
}
EOT
###
awk -f bhappy.awk
### wont work as is
export _BARF
awk -v _fout_="/tmp/_barfmeup" -f bhappy2.awk
. /tmp/_barfmeup
### might and magic
awk -v _fout_="/tmp/_barfmeup" -f bhappy2.awk
. /tmp/_barfmeup
###
###
###
echo "There was a showdown this place: $_BARF"
-------------
just counting cards:
-------------
./bhappy.sh
Before anything goes: 888
Right after first fighting: 999
in awk, x=1100, envB=1100.
There was a showdown this place: 1201
-------------