problem with using wildcards in case statement in unix?

Tag: unix Author: mingcchen01 Date: 2009-08-15
in localpath i have files with names 
myfile1_20090821.dat
myfile2_20090831.dat
myfile3_20090811.dat
myfile4_20090822.dat
myfile5_20090825.dat
type="OP"
module="abc"
if [ $type == 'OP' ]; then
case $module in
abc) x=1
     while [ $x -le 5 ]
     do
     INPUT_FILE[$x]=`ls localpath/myfile$x*.dat`
     x=$(( $x + 1 ))
     done;;
*) echo "not.......";;
esac
fi

its giving error :ls localpath/myfile$1*.dat not found

plz help me

Best Answer

Basic script looks valid, but, will only work if you run it from the parent directory of " localpath"

i.e. if you do an 'ls' from the directory where you are running the script you should see the localpath directory listed.

Try fully qualifiying the directory.

Other Answer1

My version of your program:

#!/usr/bin/bash

type="OP"
module="abc"
if [ $type == 'OP' ]; then
case $module in
abc) x=1
     while [ $x -le 5 ]
     do
     INPUT_FILE[$x]=`ls localpath/myfile$x*.dat`
     x=$(( $x + 1 ))
     done;;
*) echo "not.......";;
esac
fi

Gives no error messages. Do you have a shebang line in your version?

Actually, mine works without the shebang also. I'm using Cygwin.