[Top][All Lists]
[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: |
Peng Yu |
Subject: |
Re: [bug-gawk] How to take some variables from bash to awk? |
Date: |
Fri, 16 Nov 2012 09:14:55 -0600 |
On Fri, Nov 16, 2012 at 9:00 AM, 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
I see that I should use ${options[*]} instead.
> 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)
>
> --
> Regards,
> Peng
--
Regards,
Peng