bash, (g)awk, local variables - Quoting Rules

franz.reitinger franz.reitinger at htl-wels.at
Sat Jun 30 18:20:13 UTC 2012


> To send in variable values from outside awk, you need to define them
> on the command line:
>
> awk -v mybash_a=$a -v mybash_b=$b '<awk script>'
>
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"'")}'

/franzR
/* 
 ************************************************************
 * Mail checked by Avira virus scanner (mail.htl-wels.at).
 ************************************************************
*/

 




More information about the ubuntu-users mailing list