Script

Hello people i need help, i want to do a script in ksh with a menu.
For example
menu
1) view messages
2)view swap

and when a press 1

makes a cat /var/adm/messages. i think somethin like this

while (opcion != 0) do
echo "1) Verificacion Filesystem"
echo "2) Verificacion del hardware"
echo "3) Verificacion de messages"
echo "0) Salir "
done

read opcion
case $opcion in
1) cat /var/adm/messages ;;
2) echo pd -v;;
0) opcion=0 ;;
esac

when a run this said that opcion is not declarated o something like that .
I need help Thank you for your time.

Change the logic of your loop:

#!/bin/ksh

while : ; do

  clear
  echo "1) Verificacion Filesystem"
  echo "2) Verificacion del hardware"
  echo "3) Verificacion de messages"
  echo "0) Salir "

  read opcion

  case $opcion in
    1) cat /var/adm/messages ;;
    2) echo pd -v;;
    0) exit 0 ;;
  esac
  
done

Regards

why cant u try with usage and getopts:

USAGE="1) Verificacion Filesystem \n
\t 2) Verificacion del hardware \n
\t 3) Verificacion de messages \n
\t 0) Salir \n"

while getopts 1230 opt
do
case $opt in
1)
2)
3)
0)
esac
done

if [[ $# -ne 1 ]] then
echo "Error in parameter"
fi

By having like this u can enter ur choice in command prompt itself.
like: <pgm name> 1