Skip to main content
ertius.org

checking if a command exists in $PATH

I've spent a bunch of time putting my dotfiles in git and making them portable between machines, and so I've been tidying things up a bit and using some modern (late 90's) shell features. One specific thing is checking if a command exists:

-[ -e $(which github-copilot-cli) ] && eval "$(github-copilot-cli alias -- "$0")"
+command -v github-copilot-cli && eval "$(github-copilot-cli alias -- "$0")"

Which also will work if the command is an alias or function.