« Back to Index

Bash read the user input and react to it

View original Gist on GitHub

Bash read user input.sh

echo "Hello, what's your name?"

read users_name

echo "Hi $users_name"

echo "Do you want to continue? (y)es or (n)o"

read cont

if [ $cont == "y" ] || [ $cont == "Y" ] ; then
  echo "Cool, let's keep going."
else
  echo "Sorry to see you go. Bye"
fi

read -p "👉  Would you like to to <something>? (y/N) " -r
echo
if [[ $REPLY =~ ^[Nn]$ ]]; then
  echo "❌  Stopping setup."
  exit 1
fi