Skip to content

Commit

Permalink
Improve conditionals in functions.bash.
Browse files Browse the repository at this point in the history
Use double brackets and regular expressions where possible.
  • Loading branch information
xwmx committed Jul 7, 2020
1 parent 97e0354 commit 25ab942
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions functions.bash
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
###############################################################################

one() {
if [ "${1}" = "-h" ] || [ "${1}" = "--help" ]
if [[ "${1:-}" =~ ^-h$|^--help$ ]]
then
cat <<HEREDOC
Usage:
Expand Down Expand Up @@ -52,7 +52,7 @@ HEREDOC
###############################################################################

two() {
if [ "${1}" = "-h" ] || [ "${1}" = "--help" ]
if [[ "${1:-}" =~ ^-h$|^--help$ ]]
then
cat <<HEREDOC
Usage:
Expand All @@ -67,7 +67,7 @@ Options:
Description:
Say 'hello'.
HEREDOC
elif [ "${1}" = "--all" ]
elif [[ "${1:-}" == "--all" ]]
then
printf "Hello, everyone!\\n"
else
Expand Down Expand Up @@ -231,7 +231,7 @@ HEREDOC
# after the name `yes` is redefined.
_YES_COMMAND="$(which yes)"
yes() {
if [ "${1}" = "-h" ] || [ "${1}" = "--help" ]
if [[ "${1:-}" =~ ^-h$|^--help$ ]]
then
cat <<HEREDOC
Usage:
Expand All @@ -247,7 +247,7 @@ Description:
A wrapper for \`yes\`, which outputs <expletive> or, by default, 'y' forever.
For more information, run \`man yes\`.
HEREDOC
elif [ "${1}" = "--quiet" ]
elif [[ "${1:-}" == "--quiet" ]]
then
"${_YES_COMMAND}" "${@}" 1> /dev/null
else
Expand Down

0 comments on commit 25ab942

Please sign in to comment.