Compose variable name

Hi,

CRT=1
LPORT=
while [ "$LPORT" != "F" ]
do
echo "Please type the Port and F when finish : (current value: $LPORT)"
readDefault -e LPORT
if [ "$LPORT" != "F" ]
then
"LISTEN_PORT"$CRT=$LPORT
$CRT++
fi

done

for i in "$CRT"; do
echo "$LISTEN_PORT$CRT"
done

If I run this I get
./listen.sh: line 32: LISTEN_PORT1=8080: command not found

How should I create that variable and then print it ?

Thanks,
Bianca

Use eval to force the lines to be evaluated twice, once to insert the $CRT value, and a second time to do the assignment or substitution.

eval "$LISTENPORT"$CRT=$LPORT
...
eval echo "\$LISTEN_PORT$CRT"

Also $CRT++ is not valid shell syntax.

This is not working neither:
Please type the Listen Port and F when finish : (current value: 8081)
8082
./listen.sh: line 32: 1+1=8082: command not found
Please type the Listen Port and F when finish : (current value: 8082)
F
+1+1

Ah, apologies, I put in an extra $ by mistake and missed a _.

eval "LISTEN_PORT"$CRT=$LPORT
...
eval echo "\$LISTEN_PORT$CRT"
1 Like