Linux script execution with user input conditions

Dear experts,

I have below scripts which has 4 program function which need to be executed based on input from terminal.

Like below

echo " Choose Complete Single Cmd as CMD or ALL : ALL or CMD?"
Here if enter any other value than ALL or CMD ..Script should end and exit.

If user enter ALL

then all 4 program function should execute.
If user enter CMD
then again from below menu user need to select option

Select the HC CMD to execute and analyse
A. State"
B. active"

If choose A

then function program "function Exe_Cmd_State" should execute
if choose B
then "function Exe_Cmd_active" should execute.
If put other value than A and B then script should stop and exit.

I have executed but getting error mentioned as below

function Exe_Cmd_State(){
                echo "#####################################################Prints the cluster status#######################################"
                echo "Executing Status..." 
                sleep 1
                echo "Done..."
                }
function Exe_Cmd_active(){
                echo "###########################################To check Active Alarms####################################################"
                echo "Executing active..."
                sleep 1
                echo "Done..."
                }

function Analysis_Cmd_state(){
               
echo ""
echo ""########################################
echo ""#   State
echo ""########################################

echo ""############ DONE #########################
                }                     
function Analysis_Cmd_active(){
               
echo ""
echo ""########################################
echo ""#   Active
echo ""########################################

echo ""############ DONE #########################
                }

echo " Choose Complete Single Cmd as CMD or ALL : ALL or CMD?"
read reply
if [[ $reply == "ALL" ]]; then
Exe_Cmd_State
Exe_Cmd_active
Analysis_Cmd_state
Analysis_Cmd_active
elif [[ $reply == "CMD" ]]; then
echo "Select the HC CMD to execute and analyse"
echo "A. State"
echo "B. active"
read reply2
else
echo "Not valid Option"
fi
if [[ $reply2 == "A" ]]; then
Exe_Cmd_State
Analysis_Cmd_state
elif [[ $reply2 == "B" ]]; then
else
echo "Not valid Option"
fi

Getting below errors while executing

if [[ $reply2 == "A" ]]; then
Exe_Cmd_State
Analysis_Cmd_state
elif [[ $reply2 == "B" ]]; then
else
echo "Not valid Option"
fi

Don't the lines in red look shady to you? :smiley:

Does your shell provide the select builtin? Which, in combination with the case ... esac construct, helps building menus in a simple way.

2 Likes