400-650-7353
ڵλã(y) > IT؛Y > linux > LinuxA֪RshellַҊ(jin)

LinuxA֪RshellַҊ(jin)

  • (li)Դ(yu)͘I(y)
  • 2021-09-28 10:42:00
  • x()
  • ֙C

ַݽȡ

Ƚ

${׃:ʼλ:L(chng)}

lȡַ12345678905λ8λ

[root@host01 ~]# x="1234567890"

[root@host01 ~]# echo ${x:4:4}

5678

lȡַ12345678903λһλ

[root@host01 ~]# x="1234567890"

[root@host01 ~]# echo ${x:2}

34567890

[root@host01 ~]# x="1234567890"

[root@host01 ~]# echo ${#x}

10

[root@host01 ~]# echo ${x:2:${#x}}

34567890

ȡַ1234567890ǰ5λ

[root@host01 ~]# x="1234567890"

[root@host01 ~]# echo ${x:0:5}

12345

[root@host01 ~]# echo ${x::5}

12345

lȡַ“A񹲺͇”ĵ3λ4λ

[root@host01 ~]# x="A񹲺͇"

[root@host01 ~]# echo ${x:2:2}

҂Ƚ

${׃:0-ʼλ:L(chng)}

 ҂Ƚȡַ“A񹲺͇”҂ȵ3λһλ

[root@host01 ~]# x="A񹲺͇"

[root@host01 ~]# echo ${x:0-3}

͇

҂Ƚȡַ“A񹲺͇”҂ȵ3λ_(ki)ʼȡ2λ

[root@host01 ~]# x="A񹲺͇"

[root@host01 ~]# echo ${x:0-3:2}

ַ1234567890߅5λ_(ki)ʼȡ3λ

[root@host01 ~]# x="1234567890"

[root@host01 ~]# echo ${x:5:3}

678

ַQ

1. ֻQһ(g)ƥY${׃/old/new}

ַ1234512345Ќһ(g)3Qxxx

[root@backup ~]# i="1234512345"

[root@backup ~]# echo ${i/3/xxx}

12xxx4512345

2. QȫƥY${׃//old/new}

ַ1234512345Ќе3Qxxx

[root@backup ~]# i="1234512345"

[root@backup ~]# echo ${i//3/xxx}

12xxx4512xxx45

ַ1234512345Ќе3Qɿַ

[root@backup ~]# i="1234512345"

[root@backup ~]# echo ${i//3/}

12451245

ַ݄h

1. ƥh${׃#*P(gun)I~}

ַhttp://www.sina.com.cnЌð̖“:”߅ַȥ

[root@backup ~]# i="http://www.sina.com.cn"

[root@backup ~]# echo ${i#*:}

//www.sina.com.cn

ַhttp://www.sina.com.cnЌһ(g)“.”߅ַȥ

[root@backup ~]# i="http://www.sina.com.cn"

[root@backup ~]# echo ${i#*.}

sina.com.cn

2. L(chng)ƥh${׃##*P(gun)I~}

ַhttp://www.sina.com.cnЌ“http://”߅ַȥ

[root@backup ~]# i="http://www.sina.com.cn"

[root@backup ~]# echo ${i##*\/}

www.sina.com.cn

ַhttp://www.sina.com.cnЌһ(g)“.”߅ַȥ

[root@backup ~]# i="http://www.sina.com.cn"

[root@backup ~]# echo ${i##*.}

cn

ַhttp://www.sina.com.cnЌһ(g)“w”߅ַȥ

[root@backup ~]# i="http://www.sina.com.cn"

[root@backup ~]# echo ${i##*w}

.sina.com.cn

3. ƥh${׃%P(gun)I~*}

ַhttp://www.sina.com.cnЌ߅һ(g)“.”߅ַȥ

[root@backup ~]# i="http://www.sina.com.cn"

[root@backup ~]# echo ${i%.*}

http://www.sina.com

Ӌ㮔ǰűP(pn)“/”օ^ĴűP(pn)ʹ

[root@backup ~]# df

Filesystem 1K-blocks Used Available Use% Mounted on

devtmpfs 487168 0 487168 0% /dev

tmpfs 497828 0 497828 0% /dev/shm

tmpfs 497828 7636 490192 2% /run

tmpfs 497828 0 497828 0% /sys/fs/cgroup

/dev/sda3 11523072 1674024 9849048 15% /

/dev/sda1 520868 156640 364228 31% /boot

tmpfs 99568 0 99568 0% /run/user/0

t֘R15%ȡ(li)xֵo׃i

[root@backup ~]# df|grep "/$"

/dev/sda3 11523072 1674100 9848972 15% /

[root@backup ~]# df|grep "/$"|awk '{print $5}'

15%

[root@backup ~]# i=$(df|grep "/$"|awk '{print $5}')

[root@backup ~]# echo $i

15%

ַ“15%”е“%”ȥ

[root@backup ~]# echo ${i%\%*}

15

4. L(chng)ƥh${׃%%P(gun)I~}

ַhttp://www.sina.com.cnЌ߅һ(g)“.”߅ַȥ

[root@backup ~]# i="http://www.sina.com.cn"

[root@backup ~]# echo ${i%%.*}

http://www

ַ׃ʼֵ̎

ʹecho ${׃:-ֵ}ķʽݔ׃ֵ׃ھݔھݔO“ֵ”

׃xӡ׃xֵ;׃xڴӡOֵ

[root@host01 ~]# x="1234567890"

[root@host01 ~]# echo ${x:-abc}

1234567890

[root@host01 ~]# unset x

[root@host01 ~]# echo ${x:-abc}

abc

¡LinuxA֪RshellַҊ(jin)ю

>>ĵַhttp://www.76097.cn/zhuanye/2021/70185.html

THE END  

•:վй(yu)͘I(y)δ(jng)SɲDd

1 g

2 ČW(xu)v

3 Ă(g)Ĺ

@ȡyԇY
  • ǰǰ
  • 󔵓󔵓
  • “(lin)W(wng)I(yng)N(xio)“(lin)W(wng)I(yng)N(xio)
  • JavaJava
  • LinuxӋLinux
  • Python+˹Python
  • Ƕʽ“(lin)W(wng)Ƕʽ
  • ȫ\I(yng)ȫ\I(yng)
  • ܛyԇܛyԇ
  • ҃OӋ҃OӋ
  • ƽOӋƽOӋ
  • OӋ
  • W(wng)(y)OӋW(wng)(y)OӋ
  • ȫ·UI/UEOӋUIOӋ
  • VR/ARΑ_(ki)l(f)VR/AR
  • W(wng)j(lu )ȫW(wng)j(lu )ȫ
  • ýwcҕl\I(yng)ýw
  • ֱ؛ֱ؛
  • ܙCܛ_(ki)l(f)ܙC
 

ͨfast track

_(ki)r(sh)gTIME