公告
财富商城
积分规则
提问
发文
2019-01-04 03:55发布
一纸荒年 Trace。
x=3 A=`echo $A|awk '{print $x}'` echo $A
doesnt print 3. How can i use variables with awk*
Uh, what's the point of echoing $A? It just creates a useless fork and pipe.
$A
x=3 A=`awk -v y=$x 'BEGIN {print y}'` echo $A
And while I'm at it, this seems like a convoluted and expensive way to write A=$x :-)
A=$x
Pass variables to awk with the -v flag.
awk
-v
x=3 A=`echo $A|awk -v y=$x '{print y}'` echo $A
You can use the variables of shell by this way: "'$your-shell-variable'" or '$your-shell-variable'. The former considers the variable as string, while the later considers it as number. The following is the code you want:
"'$your-shell-variable'"
'$your-shell-variable'
x=3 A=`echo $A|awk '{print "'$x'"}'` echo $A
最多设置5个标签!
Uh, what's the point of echoing
$A
? It just creates a useless fork and pipe.And while I'm at it, this seems like a convoluted and expensive way to write
A=$x
:-)Pass variables to
awk
with the-v
flag.You can use the variables of shell by this way:
"'$your-shell-variable'"
or'$your-shell-variable'
. The former considers the variable as string, while the later considers it as number. The following is the code you want: