Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在我的.bashrcI 别名bat中,如果它安装了[ -f /usr/bin/bat ] && alias cat='bat -pp'
.bashrc
bat
[ -f /usr/bin/bat ] && alias cat='bat -pp'
这工作正常,但如果bat被卸载,别名会被破坏,所以我试图让别名在运行时进行检查,但下面的内容被破坏了。如何测试bat别名内部?
alias cat='if [ -f /usr/bin/bat ]; then bat -pp $@; else /usr/bin/cat $@; fi'
但是如果 bat 被卸载
这不像你一直在卸载东西。我会这样做:
if hash bat 2>/dev/null; then alias cat='bat -pp' fi
无论如何,使用一个函数。
cat() { if hash bat 2>/dev/null; then bat -pp "$@" else command cat "$@" fi }