[dywang@ip114 ~]$ sudo /sbin/blkid /dev/vda2 /dev/vda2: LABEL="crt-boot" UUID="364e680a-fb91-4783-8238-f7c83af8a1e3" BLOCK_SIZE="1024" TYPE="ext4" PARTUUID="68f5d32f-4de5-43a1-9a67-c7f303e9eee8"
#
開頭,表示取『最小的那一段』。
[dywang@ip114 ~]$ uuid=$(sudo /sbin/blkid /dev/vda2); echo $uuid /dev/vda2: LABEL="crt-boot" UUID="364e680a-fb91-4783-8238-f7c83af8a1e3" BLOCK_SIZE="1024" TYPE="ext4" PARTUUID="68f5d32f-4de5-43a1-9a67-c7f303e9eee8" [dywang@ip114 ~]$ uuid=${uuid#*D=\"}; echo $uuid 364e680a-fb91-4783-8238-f7c83af8a1e3" BLOCK_SIZE="1024" TYPE="ext4" PARTUUID="68f5d32f-4de5-43a1-9a67-c7f303e9eee8"
##
開頭,表示符合的最長的一段。
[dywang@ip114 ~]$ uuid=$(sudo /sbin/blkid /dev/vda2); echo $uuid /dev/vda2: LABEL="crt-boot" UUID="364e680a-fb91-4783-8238-f7c83af8a1e3" BLOCK_SIZE="1024" TYPE="ext4" PARTUUID="68f5d32f-4de5-43a1-9a67-c7f303e9eee8" [dywang@ip114 ~]$ uuid=${uuid##*D=\"}; echo $uuid 68f5d32f-4de5-43a1-9a67-c7f303e9eee8"
%
開頭 ,表示取『最小的那一段』。
[dywang@ip114 ~]$ uuid=$(sudo /sbin/blkid /dev/vda2); echo $uuid /dev/vda2: LABEL="crt-boot" UUID="364e680a-fb91-4783-8238-f7c83af8a1e3" BLOCK_SIZE="1024" TYPE="ext4" PARTUUID="68f5d32f-4de5-43a1-9a67-c7f303e9eee8" [dywang@ip114 ~]$ uuid=${uuid%=\"*}; echo $uuid /dev/vda2: LABEL="crt-boot" UUID="364e680a-fb91-4783-8238-f7c83af8a1e3" BLOCK_SIZE="1024" TYPE="ext4" PARTUUID
%%
開頭 ,表示取『最長的那一段』。
[dywang@ip114 ~]$ uuid=$(sudo /sbin/blkid /dev/vda2); echo $uuid /dev/vda2: LABEL="crt-boot" UUID="364e680a-fb91-4783-8238-f7c83af8a1e3" BLOCK_SIZE="1024" TYPE="ext4" PARTUUID="68f5d32f-4de5-43a1-9a67-c7f303e9eee8" [dywang@ip114 ~]$ uuid=${uuid%%=\"*}; echo $uuid /dev/vda2: LABEL
[dywang@ip114 ~]$ uuid=$(sudo /sbin/blkid /dev/vda2); echo $uuid /dev/vda2: LABEL="crt-boot" UUID="364e680a-fb91-4783-8238-f7c83af8a1e3" BLOCK_SIZE="1024" TYPE="ext4" PARTUUID="68f5d32f-4de5-43a1-9a67-c7f303e9eee8"
/
將字串變數 uuid 中的等號 "UUID=" 取代成冒號 ":",只取代第一個。
[dywang@ip114 ~]$ uuid=$(sudo /sbin/blkid /dev/vda2); echo ${uuid/UUID=/:} /dev/vda2: LABEL="crt-boot" :"364e680a-fb91-4783-8238-f7c83af8a1e3" BLOCK_SIZE="1024" TYPE="ext4" PARTUUID="68f5d32f-4de5-43a1-9a67-c7f303e9eee8"
/
將字串變數 uuid 中的等號 "UUID=" 取代成冒號 ":",取代所有。
[dywang@ip114 ~]$ uuid=$(sudo /sbin/blkid /dev/vda2); echo ${uuid//UUID=/:} /dev/vda2: LABEL="crt-boot" :"364e680a-fb91-4783-8238-f7c83af8a1e3" BLOCK_SIZE="1024" TYPE="ext4" PART:"68f5d32f-4de5-43a1-9a67-c7f303e9eee8"
/dev/vg_crt/swap
如下,使用變數變化請取出uuid編號,不含雙引號。
[dywang@ip114 ~]$ uuid=$(sudo /sbin/blkid /dev/vg_crt/swap); echo $uuid /dev/vg_crt/swap: UUID="659acc86-0a0f-4983-bdf7-b3e660f1d1ed" TYPE="swap"