views:

60

answers:

5

I have the below line in the unix shell script. I want to exclude test.jar in WEB-INF/lib being added to the CLASSPATH. How can i do it?

for file in WEB-INF/lib/*jar ; 

do


CLASSPATH=$CLASSPATH:$PWD/$file

done
A: 
PWD=$(pwd)

for file in WEB-INF/lib/*jar ; do
    [ "$file" != "test.jar" ] && {
        CLASSPATH="${CLASSPATH}:${PWD}/${file}"
    }
done

The code between the braces is only entered if file is not 'test.jar' , tweak to suit your needs.

Tim Post
A: 

Something like

#!/bin/sh
...
PWD=`pwd`
for file in `ls $PWD/WEB-INF/lib | grep *.jar | grep -v test.jar`
   CLASSPATH=$CLASSPATH:$file
end
Josh Kerr
don't do that. use shell expansion.
ghostdog74
+2  A: 
for file in WEB-INF/lib/*jar;
do
if [ $file != "WEB-INF/lib/test.jar" ]; then
CLASSPATH=$CLASSPATH:$PWD/$file
fi
done

I have not tried it.

Paul
put a space: `[ $file`
ghostdog74
and add `WEB-INF/lib/` to `test.jar`. I've tried to edit but code formatting disappears.
mouviciel
Done. Thanks :)
Paul
Thanks a lot for the info
Arav
+1  A: 
#!/usr/bin/bash
shopt -s extglob
for file in WEB-INF/lib/!(test).jar
do
  CLASSPATH="$CLASSPATH:$PWD/$file"
done
Ignacio Vazquez-Abrams
A: 
shopt -s extglob  
CLASSPATH=$CLASSPATH:$(ls !(test).jar|sed "s@^@$PWD/@"|tr "\n" ":"|sed 's/:$//')

Or

CLASSPATH=$CLASSPATH:$(ls !(genre).txt|awk '{$0="'$PWD'/"$0}1' ORS=":")
ghostdog74