) are special token characters in the syntax of
bash that are used in a number of operators including:
(...) subshell construct
func() compound-command function definitions
$(...) command substitution
>(...) process substitution
((...)) arithmetic evaluation construct
$((...)) arithmetic expansion
a+=(...) array assignment operators
?(...) glob operators (with extglob)
[[ (a && b) || (c && d) ]] grouping conditional expression operators
[[ ... =~ ...(...)... ]] regexp operator.
echo a=(b) is a syntax error, but not
echo a) is a syntax error, unless there was an opening
( in the previous lines part of one of the constructs above.
While it may be possible to write a readline hook that adds quotes where needed around
) to avoid a syntax error, it would be considerable effort as it would mean doing a full parsing of the shell syntax.
A better approach may be to use a shortcut that quotes the current word when you realise too late that it contains characters special to the shell.
bindkey -s '\e#' '\C@\eb\Cx\Cx\e"'
To have Alt+# quote the current word.
Or an approximation with
bash (also assuming
bind "\"\e#\": \"'\e \eb'\C-X\C-X\""