bash的工作特性之命令执行状态返回值和命令行展开所涉及的内容
bash的基础特性:命令的执行状态结果
bash通过状态返回值来输出此结果:
成功:0
失败:1-255
命令执行完成之后,其状态返回值保存于bash的特殊变量$?中。
[root@localhost ~]# ls
anaconda-ks.cfg
[root@localhost ~]# echo $?
0
[root@localhost ~]# asd
-bash: asd: command not found
[root@localhost ~]# echo $?
127
[root@localhost ~]#
bash的基础特性:命令行展开
{}:可承载一个以逗号分隔的路径列表,并能够将其展开为多个路径;
例如:/tmp/{a,b} 相当于 /tmp/a /tmp/b
实例
- 创建/tmp目录下的:ac, ad, bc, bd
[root@localhost ~]# mkdir -pv /tmp/{a_c,a_d,b_c,b_d} mkdir: created directory ‘/tmp/a_c’ mkdir: created directory ‘/tmp/a_d’ mkdir: created directory ‘/tmp/b_c’ mkdir: created directory ‘/tmp/b_d’ [root@localhost ~]# ll /tmp total 8 drwxr-xr-x. 2 root root 6 Mar 11 22:46 a_c drwxr-xr-x. 2 root root 6 Mar 11 22:46 a_d drwxr-xr-x. 2 root root 6 Mar 11 22:46 b_c drwxr-xr-x. 2 root root 6 Mar 11 22:46 b_d
- 创建目录结构
[root@localhost ~]# mkdir -pv /tmp/mylinux/{bin,boot/grub,dev,etc/{rc.d/init.d,sysconfig/network-scripts},lib/modules,lib64,proc,sbin,sys,tmp,usr/local/{bin,sbin},var/{lock,log,run}} mkdir: created directory ‘/tmp/mylinux’ mkdir: created directory ‘/tmp/mylinux/bin’ mkdir: created directory ‘/tmp/mylinux/boot’ mkdir: created directory ‘/tmp/mylinux/boot/grub’ mkdir: created directory ‘/tmp/mylinux/dev’ mkdir: created directory ‘/tmp/mylinux/etc’ mkdir: created directory ‘/tmp/mylinux/etc/rc.d’ mkdir: created directory ‘/tmp/mylinux/etc/rc.d/init.d’ mkdir: created directory ‘/tmp/mylinux/etc/sysconfig’ mkdir: created directory ‘/tmp/mylinux/etc/sysconfig/network-scripts’ mkdir: created directory ‘/tmp/mylinux/lib’ mkdir: created directory ‘/tmp/mylinux/lib/modules’ mkdir: created directory ‘/tmp/mylinux/lib64’ mkdir: created directory ‘/tmp/mylinux/proc’ mkdir: created directory ‘/tmp/mylinux/sbin’ mkdir: created directory ‘/tmp/mylinux/sys’ mkdir: created directory ‘/tmp/mylinux/tmp’ mkdir: created directory ‘/tmp/mylinux/usr’ mkdir: created directory ‘/tmp/mylinux/usr/local’ mkdir: created directory ‘/tmp/mylinux/usr/local/bin’ mkdir: created directory ‘/tmp/mylinux/usr/local/sbin’ mkdir: created directory ‘/tmp/mylinux/var’ mkdir: created directory ‘/tmp/mylinux/var/lock’ mkdir: created directory ‘/tmp/mylinux/var/log’ mkdir: created directory ‘/tmp/mylinux/var/run’ [root@localhost ~]# tree /tmp/mylinux /tmp/mylinux ├── bin ├── boot │ └── grub ├── dev ├── etc │ ├── rc.d │ │ └── init.d │ └── sysconfig │ └── network-scripts ├── lib │ └── modules ├── lib64 ├── proc ├── sbin ├── sys ├── tmp ├── usr │ └── local │ ├── bin │ └── sbin └── var ├── lock ├── log └── run 24 directories, 0 files
本文来自投稿,不代表Linux运维部落立场,如若转载,请注明出处:http://www.178linux.com/92055