Kevin_306

学习笔记-SHELL脚本编程基础-取值(二)20210331

上课练习:

实例1:取值

[02:11:36 root@centos7-kevin306 ~]#ll
total 12
-rw-------. 1 root root 1878 Jan 26 22:28 anaconda-ks.cfg
drwxr-xr-x. 2 root root    6 Jan 26 22:59 Documents
-rw-r--r--. 1 root root 1909 Jan 26 22:29 initial-setup-ks.cfg
-rwxr-xr-x. 1 root root  495 Mar 31 02:02 mail.sh
[02:11:47 root@centos7-kevin306 ~]#
[02:11:48 root@centos7-kevin306 ~]#ll |tail -n +2 |tr -s " "| cut -d " " -f 3,9
root anaconda-ks.cfg
root Documents
root initial-setup-ks.cfg
root mail.sh

 

 实例2:用正则表达式取/boot下面文件的第三列和第九列

#ll /boot/ |tail -n +2 |tr -s " "| cut -d " " -f 3,9

 

 语法中可以正常执行,但是我们换成脚本,用脚本来执行看看有什么不一样?

 结果提示报错了?这是为什么呢?

原来脚本中不能使用别名,ll是个别名,alias ll='ls -l --color=auto'

 替换掉ll,修改后执行

 执行成功,#bash boot.sh ,取出了需要的值

 

 我们执行脚本的时候还可以加个x,观察执行过程

#bash -x boot.sh

 

posted on 2021-03-27 01:29  熊猫小虾  阅读(124)  评论(0编辑  收藏  举报

导航