Peter
Peter

Reputation: 155

Unexpected condition error in a ksh script

I am new to ksh programming and wonder why the following code does not work:

#!/bin/ksh
set -A tables 44 45 46 47 48 49 50

for i in ${tables[@]}
  do
  if [[$i -eq 48 ]]; then
  echo "processing table${i}_Ge65"
  echo "processing table${i}_Lt65"
  fi
  echo "processing table${i}_A"
  echo "processing table${i}_B"
done

The error message is that

[[44: not found [No such file or directory]

for every number in the array. It seems to me that ksh treats $i as a filename instead of an expression. Any suggestion on why and how to fix this?

Thanks,

Peter

Upvotes: 0

Views: 72

Answers (1)

glenn jackman
glenn jackman

Reputation: 246992

Missing space after [[:

if [[ $i -eq 48 ]]; then
# ...^

This happens because [[ is actually a command not just syntax and, like any other command, a space is required to separate the command from the arguments.

Upvotes: 1

Related Questions