※ 引述《jacobcan118 (jacobcan118)》之銘言:
: /* 聽說註明使用的語言、環境
: * 問題有可能較容易被解決...
: */
: 請問在shell script有沒有簡單的command 能夠在字串裡找到符合的字元. 有想用grep但是找a會把aa 和ab都找出來, 也想過用一個while loop 加判斷.不過覺的太麻煩了.謝謝
: string=aa_ab_bb
: string=a_aab_abbb
: string=aaa_abb_bb
: string=aaaa_aab_bb
: string=aaa_ab_bb_cd_aa
: .....
: 如找aa只希望
: aa_ab_bb
: aaa_ab_bb_cd_aa
: 如找bb只希望
: aa_ab_bb
: aaa_abb_bb
: aaa_ab_bb_cd_aa
$ sh aa.sh
Please enter: aa_ab_bb
aa_ab_bb
Please enter: a_aab_abbb
Please enter: aaa_abb_bb
Please enter: aaaa_aab_bb
Please enter: aaa_ab_bb_cd_aa
aaa_ab_bb_cd_aa
$ cat aa.sh
while true
do
read -p "Please enter: " s
echo $s | egrep -e "_aa_|^aa$|^aa_|_aa$"
done