awk

1, shell var

$ word=world
$ echo hello | awk '{ print $1,$word; }'  # Both are treated as awk variables, so it
                                          # won't work

$ echo hello | awk "{ print $1,$word; }"  # Both are treated as bash variables, so $1
                                          # will not be hello, and it will fail if $1
                                          # is empty or unset.

$ echo hello | awk "{ print \$1,$word; }" # Since the $ in \$1 is escaped, bash
                                          # will change it to $1 and leave it alone
                                          # for awk to interpret. $word is replaced by
                                          # bash, with $word's value.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章