- list="str1 str2 str3"
- x="str1"
- [[ $list =~ $x ]] && echo 'yes' || echo 'no'
舉例來說,想知道某個instruction是否存在某一堆指令集中可以執行:
$ list="fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx lm constant_tsc arch_perfmon pebs bts rep_good nopl aperfmperf pni dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm sse4_1 xsave lahf_lm dtherm tpr_shadow vnmi flexpriority"
$ [[ $list =~ "rdtscp" ]] && echo 'yes' || echo 'no'
no
$ [[ $list =~ "sse4_1" ]] && echo 'yes' || echo 'no'
yes
$ [[ $list =~ "avx" ]] && echo 'yes' || echo 'no'
no
$ [[ $list =~ "mmx" ]] && echo 'yes' || echo 'no'
yes
_EOF_
沒有留言:
張貼留言