howto use a for(( exp1; [ test exp2 ]; exp3 )); construct

Hi,
I am fairly novice at bash but not bad at C and so wondered if a for loop could be done as shown below:

#!/bin/sh

echo "Enter some strings , terminate with a single 'x':";
REPLY=;

#I am trying to replace this with a arithmetic for statement:
j=0;
while [ "${REPLY:0:1}" != "x" ];  do
  ((j++));

# My logic:  This works (1 is true):
# for((j=1; 1 ; j++ )); do  

# So shouldn't the test statement in here evaluate to 1 or 0 and work too?   

# for((j=1; [ "${REPLY:0:1}" != "x" ]; j++ )); do

# That gets this error line:
# syntax error: operand expected (error token is "[  != . ] ")

# I tried variants of the following and still no luck.
 
# for((j=1; [[ "${REPLY:0:1}" != "x" ]] ; j++ )); do
# for((j=1; ([ "${REPLY:0:1}" != "x" ]) ; j++ )); do
# for((j=1; (( [[ "${REPLY:0:1}" != "x" ]] )); j++ )); do

# Can it be done at all?

  read 
  echo "${REPLY}";
done;
echo "goodbye";

Am I nuts?
Thanks, Howard

The only way I could make it work (so far ...):

[highlight=bash]
#! /bin/bash

echo -n "Input: " ; read INPUT

for (( INDEX=0; $INDEX<${#INPUT}; INDEX++ ))
do
if [ "${INPUT:$INDEX:1}" == "x" ]
then
break
else
echo "${INPUT:$INDEX:1}"
fi
done

exit 0
[/highlight]

Why? That for syntax is non-standard.

The second expression must be an arithmetic expression, not a command.

Use the standard syntax:


j=0
while [ "${REPLY:0:1}" != "x" ]
do
read
j=$(( $j + 1 ))
done

The "standard syntax' is fine.
I had a feeling what I was trying to do was just plain wrong , but
there was a grain of uncertainty and I'm stubborn...
...like Dr. House's there! Nice effort.
I guess it's that challenge thing.
Thanks to both of you. Nice forum youhave here.
Howard();