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";
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();