Reputation: 39366
In zsh, is there a way to turn off interactive mode (specifically aliases) within a script that has been sourced interactively?
For example, if I define in foo.zsh
:
#!/bin/zsh
a ha
and then do
alias a=echo
./foo.zsh
I get an error, because the alias is not applied; but if I do
. ./foo.zsh
I get ha
.
Is there a way, within foo.zsh
, to disable the alias a
, even if it has been sourced with .
?
Upvotes: 4
Views: 1347
Reputation: 17916
This is documented pretty clearly in the manual:
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.
but you don't need to turn off interactive mode just to prevent alias expansion:
$ setopt no_aliases
$ . ./foo.zsh
./foo.zsh:3: command not found: a
$ setopt aliases
$ . ./foo.zsh
ha
Upvotes: 1