Code checking for all values in the same if statement.

I am trying to set up a variable based on the name of the file.

function script_name {

if [ $1='pms.upload.log' ]
then
job_name='MONITOR'
return job_name;

elsif [ $1='pms.download.log'
then
job_name='REJECT'
return job_name

elif [ $1='pms.pre.mon.log' ]
then
job_name='VERSION'
return job_name

fi
}
for i in `ls *log`
do
script_name $i
done.

For some reason the conditon in 1st if condition is being evaluated to true all the times.

Any help is appreciated.
:confused:

Ignoring the obvious typos in your code, the problem
seems to be due to the use of the test(1) utility.
(man test or man [ for further information).

When you use the [..] form of the test utility you must put
a space after the first bracket and before the closing
bracket for test(1) to interpret the contents correctly.

  • Finnbarr

There are spaces before and after the ]. I am able to echo the file name as is from the first if but it should only go to the first 'if' if it satisfies the condition in it.:mad:

I found it . There should be a space after and before the '=' in between the braces.
Damn Unix.:smiley: :wink:

The brackets seems to be properly surrounded by whitespace. But the equals sign is not. This is legal:
[ "$string" ]

and it test whether or not string is null. If effect that what is being tested in this code.

Even when the spaces are added, the code will fail is $1 is null. There must be three things inside the brackets.

"$1" would solve that.

Late again... :smiley: