In bash I can do:
#!/bin/bash
validate() {
if [[ "$BASH_COMMAND" == whoami ]]; then
return 1
else
return 0
fi
}
set -T
trap 'validate' DEBUG
shopt -s extdebug
so that if I run whoami nothing happens.
How can I achieve the same in zsh ? I've looked at preexec but I couldn't find much information in the documentation
bashtoo) to usewhoami () { false; }? – Kusalananda Feb 22 '24 at 13:14whoami() falsewould be enough. In Korn-like shells including bash and zsh, you can also dowhoami() ((0))– Stéphane Chazelas Feb 22 '24 at 13:53whoami()(())or in zsh:whoami(){!}) – Stéphane Chazelas Feb 22 '24 at 14:45whoamiwas only for illustration purposes. it was the first command I could think of – Foo Feb 22 '24 at 17:15