I don't think it's possible to do it dinamically with case.
Of course it is. Bash isn't a shell well suited to scripting at all IMHO and should be avoided at all costs.
I suspect you are on an AIX system (btw. always say which system you work on - they all differ in some or other subtle regard and the answer you get might not work on your particular OS) and then "sh" is just a link to a ksh88. I am gonna use that as a basis for the script.
Your script will not work with "case"s like you did in the static version, but with a simple consistency check:
First, we read the output of "db2ilist" into an array:
We now have an array with all the instance names. No we will use this to display a list of them along with a choice:
Now that we have displayed the menu and gotten some user response in "$chSelect", we have to make sure the pick is valid - an integer and within the range of our array.
the first test is if the text entered is an integer number at all - only digits 0-9, nothing else. We throw these digits out and if anything remains the users pick was invalid. Otherwise we copy this to a predefined integer variable.
The next test is if it is a "0", which means "Abort" - we exit.
Then a test, if it is between 1 and the maximum index of our array - if no, we complain and exit (start over?) if yes, we have a valid answer and continue.
I hope everything is well understandable from my comments. some of the not-so-obvious devices explained:
"${#arrayname[*]}" expands to the number of elements in the array.
"typeset -u" declares a variable which content is automatically converted to upper case upon load. Sort-of a built-in "toupper()" function.
I hope this helps.
bakunin
These 2 Users Gave Thanks to bakunin For This Post:
HI
I want to create a date folder and then a log file under it, which will hold all output of shell script. Say shell script abc.sh runs every day and I want to redirect the output of abc.sh > /opt/bea/wls81/Pkmtest/$(date +%Y%m%d)/ant.log.
Here date should always change according to system... (2 Replies)
Hi Guru's,
Eventhough I know basic shell scripting, Iam not an expert.
Can any one help me to get a logic/answer for the below requirement:
I've to create an output file "outputfile.txt" from many datafiles (ex: abc.dat, xyz.dat).
Header record layout for "outputfile.txt" should be... (7 Replies)
I'm using the korn shell and trying to create a case statement from the contents of a file that is changed regularly,
each line of the file has three fields,
eg
track1 202.111.111.111 99
room7 222.111.222.333 76
I'm using awk to select each variable. I've been unable to figure out how to... (5 Replies)
This my script
ls *.ksh
ls *.ksh > a.txt
i=1
cat "a.txt" | while read a
do
if
then
echo "abc"
echo "abc" > m.ksh
echo "m.ksh" >> a.txt
i=2
fi
echo $a
done
ls *.ksh
--------------------------
My Output is
a.ksh - > first ls *.ksh (1 Reply)
Hi people,
I am writing a korn shell script, and one of the command gives an output something like below:
release.label.2010.03.02
objects:
/project/path/to/some/file_name.ksh
/project/path/another/file_name01.dat
I have to retrieve the file paths one by one & use them as... (9 Replies)
Hello Unix Gurus :
It would be really appreciative if can find a solution for this .
I have records in a file .
I need to Capitalize the records based on condition .
For Example i tried the following Command
COMMAND -->
fgrep "2000YUYU" /export/home/oracle/TST/data.dat | tr '' ''... (12 Replies)
I am attempting to create a script that would allow me to list all the instances associated with a DB2 and then prompt the user to choose which one to issue the db2profile command against. I use the db2 command db2ilist to get a list of the instances for a particular server, but the number of... (1 Reply)
I ran the following command.
cat abc.c > abc.c
I got message the following message from command cat:
cat: abc.c : input file is same as the output file
How the command came to know of the destination file name as the command is sending output to standard file. (3 Replies)
Hi All,
<Re-posting in Correct group>
I'm trying to select all the files in a folder that starts with a particular name format and are created in a gven date range using 'ls' command...but i'm not successful....
Example : I'm trying to see all the text files in a folder who names start... (6 Replies)
I am trying to create some variables based on the input by the user, say if user entered 3 then 3 variables and if 5 then 5 variables.
I am using a for loop
for (( i=1; i <= $num; i++ ))
do
x="num"
x+=$i
done
When i am using echo $x it will show num1 but now how to create variables... (3 Replies)