When you do
echo $aa
and $aa
contains b[1]
, the shell tries to handle the [
and ]
metacharacters after it expands the value of the variable. Since you (probably) have nothing in your current directory that matches b[1]
, you get an error.
You need to quote the variable reference. Replace
echo $aa
by either
echo "$aa"
or
echo $aa:q
(The :q
syntax is specific to csh and tcsh; double quotes work similarly in most shells, including csh-derived shells and sh-derived shells like bash
).