在BASH别名或函数使用AWK [英] Using awk in BASH alias or function
本文介绍了在BASH别名或函数使用AWK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经是在命令行下工作得很好的命令,而不是当我试图把它放在一个别名或功能。
I've a command that works just fine at the command line, but not when I try to put it in an alias or function.
$ awk '{print $1}' /tmp/textfile
0
这是正确的,因为0是在文本文件1的位置。
That's correct, as '0' is in position 1 of "textfile".
$ alias a="awk '{print $1}' /tmp/textfile"
$ a
1 0 136 94
这是在文本文件整行。我已经尝试了各种不同的报价,括号和反引号,我可以想像可能会奏效。我可以以各种格式得到了同样的问题。
That's the entire line in "textfile". I've tried every variety of quotes, parentheses and backticks that I could imagine might work. I can get the same problem in a wide variety of formats.
什么是我不理解?
推荐答案
您需要躲避 $
像这样:
alias a="awk '{print \$1}' /tmp/textfile"
否则,你的别名是:
Otherwise your alias is:
awk '{print }' /tmp/textfile
它打印整个文件...
Which prints the whole file...
这篇关于在BASH别名或函数使用AWK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文