I'm trying to do some shizzle with SFTP and SSH but it would seem I'm getting hung up on super-simple array declaration.
According to this, I should be able to use the following syntaxes to create an array:
[bob in ~] ARRAY=(one two three)
[bob in ~] echo ${ARRAY[*]}
one two three
[bob in ~] echo $ARRAY[*]
one[*]
[bob in ~] echo ${ARRAY[2]}
three
[bob in ~] ARRAY[3]=four
[bob in ~] echo ${ARRAY[*]}
one two three four
The part from that for me to focus on is this line:
[bob in ~] ARRAY=(one two three)
I tried replicating in my script:
#!/bin/bash
USERS=("user1" "user2" "user3")
PASSES=("pass1" "pass2" "pass3")
for i in ${!USERS[@]}; do
echo ${PASSES[i]};
done
Running this (using sh script.sh
) outputs:
script.sh: 2: script.sh: Syntax error: "(" unexpected
Why is my array declaration incorrect? Is the guide just wrong?
I know I can use:
declare -a ARRAY
and then append to it, but I like the idea of using a one-liner wherever possible.
Thanks,
${PASSES[i]}
, obviously, and usingprintf
, since it's a password that could contain anything. – Kusalananda Jun 05 '19 at 11:54