I have this script:
#!/bin/bash
USERS=("user1.com" "user2.co.uk" "user3.com")
PASSES=("pass1" "pass2" "pass3")
for i in ${USERS[@]}; do
echo ${PASSES[i]};
done
running this script outputs:
my-script.sh: line 6: user1.com: syntax error: invalid arithmetic operator (error token is ".com")
However, my values are wrapped in quotes and as far as I know, echo
isn't an arithmetic operation.
Coming from a PHP background, this is confusing. In PHP we can do:
echo gettype($string);
echo gettype($int);
which outputs
string
integer
Yet, the quotes seemingly do not do as I'd think. How do I force string usage instead of treating user1.com
as user1
.
com
?
USERS
i.e.for i in ${!USERS[@]} ...
– steeldriver Jun 5 '19 at 12:14!
before the array does in the foreach loop? (or add an answer for some free rep ;)) – treyBake Jun 5 '19 at 12:16