Please make this code elegant.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Please make this code elegant.
# 1  
Old 07-09-2008
Please make this code elegant.

Hi All,
Following is the part of my script.It does contain many for loops and is not elegant. Please feel free to suggest any changes to make this elegant.

Thanks!
nua7

Code:
for i in `ls $CATALINA_HOME/shared/lib/*.jar`;
  do
        LOCALCLASSPATH="$LOCALCLASSPATH:$i"
done

for i in `ls $CATALINA_HOME/common/lib/*.jar`;
  do
        LOCALCLASSPATH="$LOCALCLASSPATH:$i"
done

for i in `ls $CATALINA_HOME/webapps/CS-OAM/WEB-INF/lib/*.jar`;
  do
        LOCALCLASSPATH="$LOCALCLASSPATH:$i"
done

# 2  
Old 07-09-2008
With ksh you could write something like this:

Code:
for d in "$CATALINA_HOME"/@(shared|common)/lib/*jar \
         "$CATALINA_HOME"/webapps/CS-OAM/WEB-INF/lib/*.jar; do
  LOCALCLASSPATH="$LOCALCLASSPATH:$d"
done

It will work with bash and zsh too if you enable extended or ksh glob respectively:

[bash]
Code:
shopt -s extglob
for d in  ...

[zsh]
Code:
setopt kshglob
for d in ...

# 3  
Old 07-09-2008
Code:
for SUBDIR in "shared/lib" "common/lib" "webapps/CS-OAM/WEB-INF/lib"
do
        ls -1 ${CATALINA_HOME}/${SUBDIR}/*.jar | while read FILENAME
        do
                LOCALCLASSPATH="${LOCALCLASSPATH}:${FILENAME}"
        done
done


Last edited by radoulov; 07-09-2008 at 11:01 AM.. Reason: added code tags
# 4  
Old 07-09-2008
Thanks to all for the suggested changes! Will surely incorporate those in my script.
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Is there a more elegant

Hi, I am wanting to test that an argument passed is one of tstt11/2/3, tstq11/2/3 or tstp11/2/3 and I am currently doing it as below. Just wanting to know if there is a more 'elegant' way of doing this :-) arg_inst=`echo $1 | awk '{ print tolower($1) }'` if ] then echo "-... (2 Replies)
Discussion started by: newbie_01
2 Replies

2. Shell Programming and Scripting

Store the last 10 strings. A way to make it elegant?

Hello, Please find an ugly code. bouuu. It shall work onto RAM only to update from the last 10 strings from $URLTO. I shall read first : "$HOME/.fvwmoscfg/fvwmclipboardmplayerplayurl10.ini" The code works but it is very ugly. How could it be made elegant please? Thank you ... (2 Replies)
Discussion started by: french00b
2 Replies

3. UNIX for Dummies Questions & Answers

sed remove two headers; writing more elegant code

Hi there, I have two questions. First, I was wondering how to use sed to remove two header lines or two tail lines. Here I just do the same operation twice...I'm sure there is a better way. Second, and more importantly, is there a better way to have these operations use files other than... (5 Replies)
Discussion started by: mikey11415
5 Replies

4. Solaris

Elegant Solutions to kill telnet/ssh session

We have a generic user account "user1" setup on Solaris 8 that is used by an application. I dont want users to telnet/ssh using this account. Instead if they want to gain access, they must su or sudo to this after logging in with their own ID. My earlier attempts to accomplish this by disabling... (7 Replies)
Discussion started by: boshyd
7 Replies

5. Shell Programming and Scripting

Elegant gunzip of tar Contents

I am faced with a situation where I have directories of gunzipped contents bundled into a tar file. It might look something like this. x coop/batch/bin/ha90x20.gz, 632641 bytes, 1236 tape blocks x coop/batch/icm/HA90X20.icm.gz, 1821 bytes, 4 tape blocks x coop/batch/aeenv.gz, 4117 bytes, 9 tape... (2 Replies)
Discussion started by: scotbuff
2 Replies

6. Shell Programming and Scripting

more elegant way for conditional statement needed

Hi all, I have a script which gets its input from a text file (file.txt) and processes each line within a loop. I have a counter which increases by one and I want something to happen every 7th, 14th, 21st, etc. line read. Currently the code looks and works perfectly like this: ... (3 Replies)
Discussion started by: candyflip2000
3 Replies
Login or Register to Ask a Question