How To Use opt In Bash Script

How To Use opt In Bash Script,Example

This is an exmaple of how to create bash script with Opt in.

#!/bin/bash
echo "Select no. for option"
OPTIONS="Hello LinuxTribe Quit"
select opt in $OPTIONS; do
if [ "$opt" = "Quit" ]; then
echo done
exit
elif [ "$opt" = "Hello" ]; then
echo Hello World
elif [ "$opt" = "LinuxTribe" ]; then
echo "Welcome in LinuxTribe"
else
clear
echo bad option
echo "Type no. 1,2 or 3 for Hello,LinuxTribe and Quit options respectively"
fi
done

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.