bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-gawk] How to take some variables from bash to awk?


From: Davide Brini
Subject: Re: [bug-gawk] How to take some variables from bash to awk?
Date: Fri, 16 Nov 2012 16:30:37 +0100

On Fri, 16 Nov 2012 09:00:35 -0600, Peng Yu <address@hidden> wrote:

> Hi,
> 
> I want pass variables in bash to be used in awk in the following
> example. But it gives me some error that I have on idea how to fix.
> Does anybody know what is wrong? Thanks!
> 
> ~/linux/test/awk/lang/pipe/|$ cat  ./main_bash_var.sh
> #!/usr/bin/env bash
> 
> awk -v cmd="sort -k 1,1n" 'BEGIN{print cmd}{print $0 | cmd }' <<EOF
> 3 4
> 1 2
> EOF
> 
> 
> options=(-k 1,1n)
> echo address@hidden
> awk -v cmd="sort address@hidden" 'BEGIN{print cmd}{print $0 | cmd }' <<EOF
> 3 4
> 1 2
> EOF
> 
> ~/linux/test/awk/lang/pipe/|$ ./main_bash_var.sh
> sort -k 1,1n
> 1 2
> 3 4
> -k 1,1n
> awk: fatal: cannot open file `BEGIN{print cmd}{print $0 | cmd }' for
> reading (No such file or directory)
 
Awk is seeing:

awk -v cmd='sort -k' '1,1n' 'BEGIN{print cmd}{print $0 |cmd }'


-- 
D.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]