Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
$STRING音節がスペースで書かれている string があります。変数$WORDがこの文字列に少なくとも 1 つの音節を持っている場合、何らかの方法でこれを報告します。
$STRING
$WORD
あなたのソリューションは、逆であるべきときに$WORD存在するかどうかを確認します。$STRINGこれを試して:
string="run walk stand" word=walking if echo "$string" | sed -e 's/ /\n/g' | grep -Fqif - <(echo "$word") then echo "Match!" fi
grepご覧のとおり、出力を変数に保存しなくても、の結果をテストできます。
grep
ちなみに-nと同じ! -zです。
-n
! -z