3

在 zsh 中,有没有办法在以交互方式获取的脚本中关闭交互模式(特别是别名)?

例如,如果我在中定义foo.zsh

#!/bin/zsh

a ha

然后做

alias a=echo
./foo.zsh

我收到一个错误,因为没有应用别名;但如果我这样做

. ./foo.zsh

我明白了ha

有没有办法在 内foo.zsh禁用 alias a,即使它的来源是.

4

1 回答 1

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
于 2013-09-29T09:24:18.897 回答