>
The leading $
in your example is the problem. In your shell session, the $
is just your prompt marker (not something you should type). But when you copy-paste with the $
included, Bash interprets it as part of the command, and it becomes:
$for name in "${theList[@]}";do echo $name;done;
Just drop the $
when running commands inside your shell. Example:
declare -a theList=("joey" "suzy" "bobby")
for name in "${theList[@]}"; do
echo "$name"
done
Output:
joey
suzy
bobby