3

zshでは、インタラクティブにソースされたスクリプト内でインタラクティブモード(特にエイリアス)をオフにする方法はありますか?

たとえば、次のように定義するとfoo.zsh:

#!/bin/zsh

a ha

そして、する

alias a=echo
./foo.zsh

エイリアスが適用されていないため、エラーが発生します。しかし、私がそうするなら

. ./foo.zsh

私は得るha

で供給されている場合でもfoo.zsh、エイリアスを無効にする方法はありますか?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 に答える