在zsh中,有没有办法在交互式源代码的脚本中关闭交互模式(特别是别名)?
例如,如果我在foo.zsh
中定义:
#!/bin/zsh
a ha
然后再做
alias a=echo
./foo.zsh
我收到错误,因为没有应用别名;但如果我这样做
. ./foo.zsh
我得到ha
。
是否有办法在foo.zsh
内禁用别名a
,即使它来自.
?
答案 0 :(得分:1)
手册中已经清楚地记录了这一点:
INTERACTIVE (-i, ksh: -i)
This is an interactive shell. This option is set upon
initialisation if the standard input is a tty and commands are
being read from standard input. (See the discussion of
SHIN_STDIN.) This heuristic may be overridden by specifying a
state for this option on the command line. The value of this
option can only be changed via flags supplied at invocation of the
shell. It cannot be changed once zsh is running.
但您不需要为了防止别名而关闭交互模式 扩展:
$ setopt no_aliases
$ . ./foo.zsh
./foo.zsh:3: command not found: a
$ setopt aliases
$ . ./foo.zsh
ha