linuxshellunixzshzsh-zle

Why can't I grep zle from setopt?


I came across this by chance, and it's been nagging me since:

% setopt
alwaystoend
autocd
autonamedirs
...
sharehistory
shinstdin
zle
%
% setopt | grep zle
# nothing printed
%
% setopt | cat -vet
alwaystoend$
autocd$
autonamedirs$
...
sharehistory$
shinstdin$
# no zle here!

As you can see grep fails to detect zle, and piping the output of setopt to cat in order to detect any irregular characters (not that it would make more sense) shows no zle either!


Solution

  • man zshzle
    ...
     If  the  ZLE option is set (which it is by default in interactive shells) and the shell input
           is attached to the terminal, the user is able to edit command lines.
    

    Since you are piping the output of setopt to a process, the shell turns off command line editing. (Although this line of the documentation only refers to the shell input being attached to the terminal, this captures the essence of the issue. Nothing funny going on, its just that the shell is turning off the option.