Elseif & for condition in AIX

I'm using the below statements in my script

if [$selection -ge 0] && [$selection -le 7] then
   sqlplus sysadm/abcdefgh12@${dbarr[idx]} @/u1/scripts/ResetPswd.sql
elif [$selection == 8] then
   for idx in 0 1 2 3 4 5 6 7
      do
         sqlplus sysadm/abcdefgh12@${dbarr[idx]} @/u1/scripts/ResetPswd.sql
      done
else
   exit
fi

It give me the error

`elif' unexpected

Can someone please help me? Also please let me know if the for condition is correct. for condition I meant was to execute the command for all the values (idx) 0 to 7

if [ "${selection}" -ge 0 ] && [ "${selection}" -le 7 ]; then
elif [ "${selection}" -eq 8 ]; then

Can I also suggest that you take the credentials out of your sqlplus command line. Anyone running a simple ps will be able to see them whilst your database connection is active.

It might only be a short time, but if this account is a DBA (which I'm guessing that it is) then you are effectively shouting the out the number for a combination lock on your most secure safe. If no-one is listening, then you get away with it. If someone hears, it depends on their integrity if they do something with it.

Robin

If the variable idx is not defined earlier in the script, where we can't see it, the sqlplus statement in the second line above will fail.

Try this...

if [[ $selection -ge 0 && $selection -le 7 ]]
then
        sqlplus sysadm/abcdefgh12@${dbarr[idx]} @/u1/scripts/ResetPswd.sql
elif [[ $selection == 8 ]]
then
        for idx in 0 1 2 3 4 5 6 7
        do
                sqlplus sysadm/abcdefgh12@${dbarr[idx]} @/u1/scripts/ResetPswd.sql
        done
else
        exit
fi

Again, I would suggest moving the credentials out of the sqlplus command line, perhaps like this:-

if [[ $selection -ge 0 && $selection -le 7 ]]
then
        sqlplus sysadm/abcdefgh12@${dbarr[idx]} @/u1/scripts/ResetPswd.sql
elif [[ $selection == 8 ]]
then
        for idx in 0 1 2 3 4 5 6 7
        do
            sqlplus <<-EOSQL
               sysadm/abcdefgh12@${dbarr[idx]}
               @/u1/scripts/ResetPswd.sql
            EOSQL                 # Tab indented only!
        done
else
        exit
fi

You don't want to be broadcasting your most secure user credentials.

Robin