【Shell】Expansion

shell命令在执行之前会将做expasion操作,比如:

[jiangjian@localhost ~]$ ls
demo.txt  Desktop  Documents  Downloads  jenkins-2.164.1-1.1.noarch.rpm  Music  Pictures  Public  shell  Templates  test  Videos
[jiangjian@localhost ~]$ echo [[:upper:]]*
Desktop Documents Downloads Music Pictures Public Templates Videos
[jiangjian@localhost ~]$ 

expansion的种类:

  • pathname expasion:
  • tidle expasion
  • arithmetic expansion
  • brace expansion
  • parameter expansion
  • command substitution

如下是使用示例:

[jiangjian@localhost shell]$ ls *.txt # pathname expansion
a-hard-link.txt  a-soft-link.txt  b-1.txt  b.txt
[jiangjian@localhost shell]$ echo ~ #tidle expansion
/home/jiangjian
[jiangjian@localhost shell]$ echo $((1+3)) # arithmetic expansion
4
[jiangjian@localhost shell]$ mkdir {2007..2009}-{1..12} # brance expansion
[jiangjian@localhost shell]$ ls
2007-1   2007-11  2007-2  2007-4  2007-6  2007-8  2008-1   2008-11  2008-2  2008-4  2008-6  2008-8  2009-1   2009-11  2009-2  2009-4  2009-6  2009-8  a-hard-link.txt  b-1.txt
2007-10  2007-12  2007-3  2007-5  2007-7  2007-9  2008-10  2008-12  2008-3  2008-5  2008-7  2008-9  2009-10  2009-12  2009-3  2009-5  2009-7  2009-9  a-soft-link.txt  b.txt
[jiangjian@localhost shell]$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[jiangjian@localhost shell]$ file $(ls /usr/bin/* | grep bin/zip) 或者 file `ls /usr/bin/* | grep bin/zip`  # command substitution
/usr/bin/zip:        ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=7c01940c97abdf45a093c697e63ef214ea14adcf, stripped
/usr/bin/zipcloak:   ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=e0f7de70feffd0124f6350e449b8d6c7513502da, stripped
/usr/bin/zipdetails: Perl script, ASCII text executable
/usr/bin/zipgrep:    POSIX shell script, ASCII text executable
/usr/bin/zipinfo:    ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=871b5a9c440eb0a275af4db71cdd79778b1fd790, stripped
/usr/bin/zipnote:    ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=750c11ada0bec740fa2885383e678e7be5206cdd, stripped
/usr/bin/zipsplit:   ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=e259ffcdb17baf5b9599c87ad924eb51b4df53b4, stripped

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值