From b31c6dc059ee4857117c1ce34942b162c08f12a4 Mon Sep 17 00:00:00 2001 From: Pete Doherty Date: Mon, 5 Feb 2024 13:45:23 -0500 Subject: [PATCH] Add basic input validation to `select` example Report an error message and exit early from select example if input is invalid. --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 1f3a96f..62ba88e 100644 --- a/README.md +++ b/README.md @@ -780,6 +780,12 @@ A working example might look like this: PS3="Choose the package manager: " select ITEM in bower npm gem pip do + # exit early if selection is invalid + if [[ -z "$ITEM" ]]; then + >&2 echo "Invalid selection" + exit 1 + fi + echo -n "Enter the package name: " && read PACKAGE case $ITEM in bower) bower install $PACKAGE ;;