I need to code a series of menus that have four options, selectable either by the number in the menu or the name, in succession. This part I have achieved however I am struggling to find a way that should the user try to enter an invalid selection, such as the number 5 or an incorrect name, there is an echo line saying that the entry is incorrect and the menu presented again - this will happen until a correct selection is made.
I have managed to get the echo line working: "echo "Chosen option is unknown, please try again!"\\n" .
As you can see, there are three menus at present.
One asks you to select from a list of friends whose names you previously input.
The next asks you to choose a celebrity from a precoded list.
The next asks you to choose a file from a precoded list.
This is my first time working with the korn shell and I first though of gotos (if incorrect, goto line whatever) but they unfortunatly dont work
Any help would be greatly appreciated! I've been scratching my head all night about it, the answer is probably staring me in the face haha.
thanks so much for your quick response! I implemented the code and played around with it but couldnt find a way to use variables in the situation. Instead of John, Fred, Steve and bubba I need $VarFriend1, $VarFriend2, and $Varfriend3 - with these values set by the user with the previous command:
read VarFriend1 VarFriend2 VarFriend3
I seem to have trouble assigning the variable names these other variables...it just prints them as normal text.
So ideally, the code would go:
"Please enter your friends' names, seperated by spaces":
John Fred Steve (entered by user)
Then it would display these names like in the code you provided as values of $VarFriend1 $VarFriend2 and $VarFriend3.
Cheers for your help so far buddy I've felt I've gotten a lot further so far already!
I figured out a way to assign the variables, cleaned up my code a bit also and it all works. Just one more question if possible, and my internet research into the select command has so far turned up nothing. Instead of having to pick the number from the menu list, is it possible to use the name of the variable instead?
So instead of:
1) Tom
2) Dick
3) Harry
4) Quit
What would you like to choose: 3
As well as, or instead of, 3, you could write "Harry" and it would work. Obviously, the case function would throw an error if it wasn't 3 or Harry, for example you wrote Harryyy.
One more thing. I have created 3 files, FileA File B and File C. I want to set it so only FileA can be opened if Tom was selected previously, File B if Dick was selected previously, nd FileC if Harry was selected previously, else error. I figured the code might be something like:
Cheers for all your help! I have never done programming before, but you have helped learn loads.
After testing the above code i found it did not work. I am still struggling to solve how I could make the one menu's options and case arguments dependent on the user response to a previous one
Here is the question...
Create a new script, sub2, taking three parameters...
1.) the string to be replaced
2.) the string with which to replace it
3.) the name of the file in which to make the substitution
...that treats the string to be replaced as plain text instead of as a regular... (1 Reply)
The script below fails with the following error messages:
gzip: invalid option -- 'w'
Try `gzip --help' for more information.
mysqldump: Got errno 32 on write
cp: invalid option -- 'w'
Try `cp --help' for more information.
rm: invalid option -- 'w'
Try `rm --help' for more information.
... (1 Reply)
Dear all,
I'd be so grateful if I could get great feedback again for my problems.
We usually spool some text files from our system in csv format.
Unfortunately, some data contains ',' (comma) and it's rare case but when it comes to spool, that row included comma should be invalid data, due... (2 Replies)
Hi All
I have writing a Korn Shell script to execute it on many of our servers. But some servers don't have Korn Shell installed, they use Borne Shell.
Some operations like calculation don't work :
cat ${file1} | tail -$((${num1}-${num2})) > ${file2}
Is it possible to activate Korn Shell... (3 Replies)
Hi, I am getting the error
01.30 Invalid shell error
I am running the bash shell script in the korn login shell.
I have mentioned the #!/bin/bash statement in the my script but not sure why it is giving this error to me.. (4 Replies)
Dear All,
Kindly suggest on how should i proceed with the following requirement
I need to develop an interactive shell script menu which would enable the user to inquire the value of a column based on a key value . The output can be more records..
Also is it possible to do the following
1)... (2 Replies)
I am trying to find a way to allow users to select multiple options in a shell menu. I am using case and it gives menu options 1-9, how can I set this up so that it give the user the ability to choose more then one option, ie 1,2 or 3,4,5, etc... (4 Replies)
Greetings all,
I'm currently writing a shell script menu which is dynamically populated from an array. Have a question to ask about the filtering of invalid input. I'm using KSH.
A brief description of my algorithm is as follows:
1) Read in input from user and store in a variable. (a valid... (2 Replies)
well i have this code here..and it works fine in kornshell..
#!/bin/ksh
home=c:/..../
input=$1
sed '1,3d' $input > $1.out
line=""
cat $1.out | while read a
do
line="$line $a"
done
echo $line > $1
rm $1.out
however...now i want it just in normal sh mode..how to convert this?... (21 Replies)