If inside If loop

Hi All,

Below is the very simple code snippet but it si giving me syntax error

 
#!/bin/bash
#To ensure If JMS directory exists or not
ServerName=$(hostname)
#To ensure If JMS directory exists or not
echo $ServerName
if [ "$ServerName" = "usei01" || "$ServerName" = "usei02" || "$ServerName" = "usei03" ]; 
then
echo "Inside First If"
if [ -d /opt/shared -a -w /opt/shared/data/jms ];
then 
echo 'JMS mounts................exist'>>OutputResult.txt
else 
echo "JMS mounts................not exist">>OutputResult.txt
fi
echo "Outside IF"
fi

It is not reading the else and syntax error at line 7 which is my first If clause.

Just try the above code :slight_smile:

Cheers!!!
-R

1 Like

You have to write the first if clause as below.

 
if ([ "$ServerName" = "usei01" ]|| ["$ServerName" = "usei02" ]|| ["$ServerName" = "usei03" ]);then
 

;then should be in one line

1 Like

Or:

 if [ "$ServerName" = "usei01" -o "$ServerName" = "usei02" -o "$ServerName" = "usei03" ]
1 Like

Thanks Milan,

It is working for me