gpt4 book ai didi

zsh - 有没有办法在 zsh 中抑制交互模式?

转载 作者:行者123 更新时间:2023-12-04 18:29:36 25 4
gpt4 key购买 nike

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

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

#!/bin/zsh

a ha

然后做
alias a=echo
./foo.zsh

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

我得到 ha .

有没有办法,在 foo.zsh内, 禁用别名 a ,即使它来自 . ?

最佳答案

这在手册中非常清楚地记录:

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

关于zsh - 有没有办法在 zsh 中抑制交互模式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18862884/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com