Bash script gives error on array, console doesn't. (Solved)

Using applications, configuring, problems
Post Reply
Message
Author
User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

Bash script gives error on array, console doesn't. (Solved)

#1 Post by sunburnt »

I'm writing a auto USB mounter & ran into this little bug-a-boo.

This works in Xterm, I typed:
# N=1
# T[$N]=ddd
# echo ${T[$N]}
ddd

For a script I used this to test it:
#!/bin/sh
for N in 1 2 3
do
echo $N
T[$N]=$N
echo "${T[$N]}"
done

This code should print out: 112233 (one number per line).
Instead it errors with: ./test: 6: Syntax error: Bad substitution
The line: echo "${T[$N]}" doesn't work in a script like it does in Xterm.

DARN IT !!! ............. I forgot to change the "she bang" to: #!/bin/bash

Post Reply