Can zsh read reserved terminal keyword?

Viewed 30

Normally, if I type 'clear' in the shell(zsh), then the contents shown are cleared.

And, here is what I want to do.

If I type 'clear', the shell would be cleared, and also logging some message which I intend to make.

So I fixed .zshrc like below,

clear()
{
    read REPLY

    if[[[ $REPLY =~ "clear"]]
    then
        echo "some message"
    fi
}

So I expected that if I type 'clear', contents on the shell would be cleared and "some message" would also be prompted.

But only the message "some message" comes out.

How can I read that reserved "clear" command, not the string itself?

1 Answers

Your function does not clear the screen. For doing this, you have to issue a clear command. But since your function is also called clear, simply typing clear inside the function would lead to infinite recursion. As a solution, use

command clear

instead. The prefix command bypasses the function definition.

Related