Created
May 1, 2021 09:56
-
-
Save fuji44/895a5f5bb855d4ff1562ff18f82db6d3 to your computer and use it in GitHub Desktop.
シェルスクリプトでの大文字と小文字を区別しない真偽の判定処理
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
yes_or_no() | |
{ | |
case `echo "$1" | tr A-Z a-z` in | |
"y"|"yes"|"on"|"true") | |
echo "'$1' is YES!!!" | |
;; | |
"n"|"no"|"off"|"false") | |
echo "'$1' is NO!!!" | |
;; | |
*) | |
echo "Unknown argument." | |
;; | |
esac | |
} | |
yes_or_no "y" # 'y' is YES!!! | |
yes_or_no "Y" # 'Y' is YES!!! | |
yes_or_no "Yes" # 'Yes' is YES!!! | |
yes_or_no "NO" # 'NO' is NO!!! | |
yes_or_no "tRUe" # 'tRUe' is YES!!! | |
yes_or_no true # 'true' is YES!!! | |
yes_or_no false # 'false' is NO!!! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment