我正在尝试将一些功能从我的旧 .bashrc 移植到我的 .zshrc 中,但我遇到了在 bash 中有效的情况。
每当我远程登录到我的计算机时,我都会让 bash 检查$-
变量以查看它是否是交互式的。如果是,我会启动一个 emacs 服务器(如果尚未运行)并切换到我的代码目录。否则(例如,如果我使用 scp 获取文件),我不会做任何事情。
这是一段代码:
if [[ $- -regex-match "i" ]]; then
ps -u myusername | grep emacs > /dev/null
if [ $? -eq 0 ]; then
echo "emacs server already running"
else
emacsserver
fi
aliastocdtomydirectory
fi
这是 zsh 给我的错误:.zshrc:125: unrecognized condition:
$-'`
有谁知道在使用时如何解决这个错误$-
?我试过引用它,把它包装起来,$(echo $-)
但没有一个奏效。提前致谢。
编辑:如果我将代码切换为:
if [[ $- =~ "i" ]]; then
ps -u myusername | grep emacs > /dev/null
if [ $? -eq 0 ]; then
echo "emacs server already running"
else
emacsserver
fi
aliastocdtomydirectory
fi
我现在明白了:.zshrc:125: condition expected: =~
我不确定 zsh 在这里错误地解释了什么,因为我不太熟悉 zsh 的 shell 脚本的语义。有人可以为我指出如何在 zsh 中表达这种情况的正确方向吗?