私たちはスクリプトの1つを改善しようとしています。
ユーザーはいくつかのパラメータを渡し、いくつかのパラメータは5.0.3
。Jboss5.0.3GA
Jboss5.0.3GAには「5.0.3」があるので、インストールバイナリ「Jboss5.0.3GA.tar」を探してみましょう。
現在のスクリプトはkshスクリプトです。if
スクリプトで条件を使用しようとしています。
ユースケースと結果の例:
./test.sh Jboss5.0.3GA
Match found... we'll try to locate the installation binary
./test.sh Jboss5.0.3
Match found... we'll try to locate the installation binary
./test.sh 5.0.3
Match found... we'll try to locate the installation binary
./test.sh Jboss5.1.3
No Match found ... we'll be exiting the script.
ベストアンサー1
POSIXシェルのパターンマッチングはcase
この設定で行われます。ksh
また、演算子([[ x = pattern ]]
and にもコピーされます)と最新バージョンです。bash
zsh
[[ x =~ regexp ]]
だから:
case $1 in
(*5.0.3*)
install=$1.tar
echo Found;;
(*)
echo >&2 Not found
exit 1;;
esac