FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Ubuntu > Ubuntu User

 
 
LinkBack Thread Tools
 
Old 06-30-2012, 06:49 PM
Nils Kassube
 
Default bash, (g)awk, local variables - Quoting Rules

franz.reitinger wrote:
> After reading the "quoting"-rules of awk/bash I tried some different
> possibilities to access bash variables inside awk.
> The following code also works within a bash (script): (v 4.2.24)
>
> a=$(<anyFile)
> b="anyPattern"
>
> awk 'BEGIN {print index("'"$a"'","'"$b"'")}'

With so many quotes that line looks quite error prone to me. Therefore I
searched for "environment" in the gawk manual and found this solution:

export a b
awk 'BEGIN { print index(ENVIRON["a"], ENVIRON["b"]) }'


Nils

--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 

Thread Tools




All times are GMT. The time now is 04:31 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org