Current location - Recipe Complete Network - Complete cookbook - How to write a selection menu in Linux shell script?
How to write a selection menu in Linux shell script?

#!/bin/sh

echo 1.Option 1(@)

echo 2.Option 2(#)

echo 3. Option 3(&)

echo Please choose:

read -n 1 M

#The following line is a newline

echo

#echo M=$M

if [ "$M" = "@" ]

then

echo option 1

elif [ "$M" = "#" ]

then

echo option 2

elif [ "$M" = "&" ]

then

echo option 3

else

echo Error

fi

==========

The above has been tested, please note that there are spaces in some places.

There is a space before and after the square brackets

There is also a space before and after the equal sign.