关于NF和$NF的理解(笔记)

在优化history时,查资料遇到个问题:

echo $PWD | awk -F/ '{print $NF}'

不是太理解这个命令,经过查资料明白,记录以备后续复习:

-F /表示以 ’/’  分开
NF 表示的是浏览记录的的个数 
$NF 表示的最后一个Field(列),即输出最后一个字段的内容

[root@localhost usertmonitor]# pwd
/var/log/usertmonitor
[root@localhost usertmonitor]# echo $PWD | awk -F / '{print $NF}'
usertmonitor
[root@localhost usertmonitor]# echo $PWD | awk -F / '{print NF}'
4
[root@localhost usertmonitor]#

 

参考:

https://blog.csdn.net/justine_king/article/details/70303897

https://blog.csdn.net/github_33736971/article/details/54286736?depth_1-utm_source=distribute.pc_relevant.none-task&utm_source=distribute.pc_relevant.none-task

https://blog.csdn.net/qq_34685846/article/details/73224709?depth_1-utm_source=distribute.pc_relevant.none-task&utm_source=distribute.pc_relevant.none-task

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