bug-gawk
[Top][All Lists]
Advanced

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

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


From: Peng Yu
Subject: [bug-gawk] How to take some variables from bash to awk?
Date: Fri, 16 Nov 2012 09:00:35 -0600

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)

-- 
Regards,
Peng



reply via email to

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