LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   i want to make a script with case.esac (https://www.linuxquestions.org/questions/linux-newbie-8/i-want-to-make-a-script-with-case-esac-266217/)

Alexander.s 12-14-2004 04:54 AM

i want to make a script with case.esac
 
I know how to do regular the ones

#!/bin/bash
NUM=$(( RANDOM % 10 ))
case $NUM in

0) echo "zero"
1) echo "one"
2 bla bla
3 bla
4 bla
5 bla
6 bla
7 esac
8
9
*
esac

But how do i use the read command in this
i want it to read a number and say it in letters
as when you type 5 it will echo five

thanks!

mjuhannus 12-14-2004 05:22 AM

Hi

You just need to put line read NUM in it.

Here's an example:

Code:

#!/bin/bash

#NUM=$((RANDOM % 10))
echo -n "Enter a number: "
read NUM
case $NUM in

0) echo Zero ;;
1) echo One ;;
2) echo Two ;;
3) echo Three ;;
*) echo Bigger than Three ;;
esac


mjuhannus 12-14-2004 05:24 AM

oops, an error in the code
 
the case line of course without the word 'his' in the end.

Well actually i can edit the messages later so i removed it and this post useless

Alexander.s 12-14-2004 05:29 AM

np i was just going to say i figured it out :P

thanks!


All times are GMT -5. The time now is 07:16 AM.