如何使用 zsh 'command' 选项执行内置 'source' 命令?
How do I use to the zsh 'command' option to execute a the builtin 'source' command?
每次我的 shell 获取文件时,我都会尝试记录。我用的是zsh,所以进了zshenv,加了这个功能
source() {
echo "sourcing "
command source
}
我的想法是每次“source [file]”出现在我的一个点文件中并被执行时,它应该先将操作打印到终端,然后再实际获取文件。
相反,我收到了一些这样的错误
sourcing /Users/js/.cargo/env
source:2: command not found: source
sourcing /Users/js/.sources/postgres-env.sh
source:2: command not found: source
sourcing /Users/js/.oh-my-zsh/oh-my-zsh.sh
source:2: command not found: source
sourcing /Users/js/.iterm2_shell_integration.zsh
source:2: command not found: source
在 zsh 中使用 shell 'command' 选项调用 source 的正确方法是什么?
command
旨在专门调用 外部 命令。例如,如果您有 git
的别名或函数,command git
将绕过它们。
您正在寻找 builtin
命令以将命令查找限制为仅内置命令。
source() {
echo "sourcing "
builtin source ""
}
要使其在 shell 下正常工作,您可以改用此方法:
#!/usr/bin/env sh
source() {
echo "sourcing "
. ""
}
source ""
每次我的 shell 获取文件时,我都会尝试记录。我用的是zsh,所以进了zshenv,加了这个功能
source() {
echo "sourcing "
command source
}
我的想法是每次“source [file]”出现在我的一个点文件中并被执行时,它应该先将操作打印到终端,然后再实际获取文件。
相反,我收到了一些这样的错误
sourcing /Users/js/.cargo/env
source:2: command not found: source
sourcing /Users/js/.sources/postgres-env.sh
source:2: command not found: source
sourcing /Users/js/.oh-my-zsh/oh-my-zsh.sh
source:2: command not found: source
sourcing /Users/js/.iterm2_shell_integration.zsh
source:2: command not found: source
在 zsh 中使用 shell 'command' 选项调用 source 的正确方法是什么?
command
旨在专门调用 外部 命令。例如,如果您有 git
的别名或函数,command git
将绕过它们。
您正在寻找 builtin
命令以将命令查找限制为仅内置命令。
source() {
echo "sourcing "
builtin source ""
}
要使其在 shell 下正常工作,您可以改用此方法:
#!/usr/bin/env sh
source() {
echo "sourcing "
. ""
}
source ""