Using awk in BASH alias or function

后端 未结 2 1532
北海茫月
北海茫月 2020-12-14 06:35

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
<         


        
相关标签:
2条回答
  • 2020-12-14 07:29

    Use a function instead of alias

    myfunc(){ awk '{print $1}' file; }
    
    0 讨论(0)
  • 2020-12-14 07:35

    You need to escape the $ like so:

     alias a="awk '{print \$1}' /tmp/textfile"
    

    Otherwise your alias is:

     awk '{print }' /tmp/textfile
    

    Which prints the whole file...

    0 讨论(0)
提交回复
热议问题