Sponsored Content
Top Forums Shell Programming and Scripting Dynamic case creation based on output list from a command Post 302656005 by bakunin on Thursday 14th of June 2012 06:37:31 AM
Old 06-14-2012
Quote:
Originally Posted by Lem
Of course it is possible to solve the problem in many ways, but I still don't see a way to dinamically create the entries of a case command.
This is correct, i'll give you that. Sorry for misreading your post before, but i was under the impression that you mean it is not possible to solve the problem while you obviously meant it is not possible to create case-statements dynamically.


Regarding bash not being well suited for scripting.
Quote:
Originally Posted by Lem
My shells knowledge is so little that I can't discuss this topic.
But I'm a bit.. confused.
Sorry again, what i said was just an off-topic remark. The reasons for this personal opinion of mine are many but it is quite off-topic here to discuss it. If you are interested I'll send you some pointers per PM, we even have some threads here aobut the shortcomings of bash compared to ksh.

Quote:
Originally Posted by Lem
What was so wrong with my script?
Nothing at all. If you compare my script and yours closely the logic is similar. The difference is i commented it heavily (the threads O/P comes across as not so experienced in shell scripting and probably will need that to understand the flow of the program), i explained how he could implement the input checks, which come with the "case..esac" and which are missing in your script and i used the shell i suppose he already uses (ksh) because of - as stated - i suppose he works on an AIX system. The reason for this is he uses DB/2 as a database, which is from IBM. AIX is IBMs Unix derivate and it is conceivable that a company buying the database from one vendor will buy the hardware and the OS from the same vendor.

Quote:
Originally Posted by Lem
And, of course, also in bash you can use an array as you've done in ksh (moreover, it had been my first think: but then select came to my mind, and it does the work, and it's much quicker. So why not use it, if bash is available?).
"select" as well as arrays are available in ksh and bash alike - even with an identical syntax. I decided against it in my solution because i wanted better control over the output ("select" always goes to <stderr> for instance) and the program flow. It is just usually better to stick to the default shell on any system. For the same reasons i advocate the ksh here on a - probable- AIX system i would advocate using the bash on, say, a GNU/Linux system, even if i still think ksh is the better shell, but that is just personal conviction. ksh is the default shell here, bash is the one there and hence they should be used accordingly if at all possible.



Quote:
Originally Posted by Lem
LOL! Smilie
Of course you're speaking to the OP.
AIX... I'm not a sysadmin, nor my job is heavily computer related. So, AIX... (AKA "blood and tears", as someone says): I - personally - have never seen an AIX system. Smilie
Yes, that was addressing the OP. AIX evolved from being "the best MVS IBM ever created" (this was the saying back in the days of AIX 3.2.3, when i started working with it - ~1993) to one of the most widely spread and most standard-adhering Unixes at all (5L and above). If you buy hardware from IBM (the POWER6 and POWER5 processors were by far the fastest processors of their times, so many companies did exactly that) you will have to use either Linux or AIX and most companies used AIX in this case.

I hope we have sorted out the misunderstandings.

bakunin
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Creation of log file under dynamic date folder

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)
Discussion started by: pankajkrmishra
2 Replies

2. Shell Programming and Scripting

Creation of output file from list of file

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)
Discussion started by: ganapati
7 Replies

3. Shell Programming and Scripting

Creating a dynamic case statement

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)
Discussion started by: squrcles
5 Replies

4. UNIX for Advanced & Expert Users

Dynamic file creation

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)
Discussion started by: kingganesh04
1 Replies

5. Shell Programming and Scripting

Parsing dynamic data from a command output

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)
Discussion started by: kiwin1000
9 Replies

6. Shell Programming and Scripting

Conversion from Upper Case to Lower Case Condition based

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)
Discussion started by: tsbiju
12 Replies

7. Red Hat

Dynamic case creation based on output list from a command

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)
Discussion started by: slatoms
1 Replies

8. Red Hat

Command understanding the output file destination in case of standard output!!!!!

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)
Discussion started by: ravisingh
3 Replies

9. UNIX for Dummies Questions & Answers

Select all files in a folder based on creation date (ls command)

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)
Discussion started by: Satya C1
6 Replies

10. UNIX for Dummies Questions & Answers

Dynamic Variable creation

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)
Discussion started by: Raj999
3 Replies
All times are GMT -4. The time now is 01:57 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy