Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

awk, ENVIRON usage 1

Status
Not open for further replies.

w5000

Technical User
Nov 24, 2010
223
0
0
PL
hello,
can it be used with ENVIRON instead of -v?

# free=50
# size=60
# awk -va=${free} -vb=${size} 'BEGIN{printf "%3.2f\n", a/b*100}'
83.33
# awk 'BEGIN{printf "%3.2f\n", $ENVIRON["free"]/$ENVIRON["size"]*100}'
awk: 0602-562 Field $() is not correct.
The source line number is 1.
#
 
Hi

The [tt]$[/tt] sigil denotes a field. So [tt]$ENVIRON["free"][/tt] is actually [tt]$50[/tt] in this case. Just remove those [tt]$[/tt] signs.

( By the way, the free and size environment variables were [tt]export[/tt]ed, right ? They need to be, if you want subsequent processes to see them. )

Feherke.
feherke.ga
 
thank you, indeed works now
# awk 'BEGIN{printf "%3.2f\n", ENVIRON["free"]/ENVIRON["size"]*100}'
83.33
#
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top