Skip to content

Instantly share code, notes, and snippets.

@fuji44
Created May 1, 2021 09:56
Show Gist options
  • Save fuji44/895a5f5bb855d4ff1562ff18f82db6d3 to your computer and use it in GitHub Desktop.
Save fuji44/895a5f5bb855d4ff1562ff18f82db6d3 to your computer and use it in GitHub Desktop.
シェルスクリプトでの大文字と小文字を区別しない真偽の判定処理
#!/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