zshrcのZshエラー置換エラー

zshrcのZshエラー置換エラー

私の.zhsrcファイルには次のものがあります。

[[ -n "${key[Home]}"    ]]  && bindkey  "${key[Home]}"    beginning-of-line     

キーボードでHomeを押すと、行の先頭に移動しているように見えますが、これはうまく機能しているようですが、vimで.zshrcを編集して保存するたびに、SyntasticCheck zshで「誤った置換」エラーを報告します。

これは私の間違いですか、それとも文法チェッカーのバグですか?

コメントに対する編集者の回答:

いいえ、Zshの起動時にエラーは発生しません。はい、構文チェッカーはその行にエラーがあると言います。

$ sed -n /Home/l .zshrc
key[Home]=${terminfo[khome]}$
[[ -n "${key[Home]}"    ]]  && bindkey  "${key[Home]}"    beginning-o\
f-line$

編集2. zsh -vn .zshrcの出力

.zshrcファイルを次のように整理しました。

echo OK
[[ -n "${key[Home]}"    ]]  && bindkey  "${key[Home]}"    beginning-of-line
echo OK2

シェルを起動すると、OKとOK2が表示され、エラーは表示されません。しかし、これはzsh -vn .zshrcの出力です。

# /etc/zsh/zshenv: system-wide .zshenv file for zsh(1).
#
# This file is sourced on all invocations of the shell.
# If the -f flag is present or if the NO_RCS option is
# set within this file, all other initialization files
# are skipped.
#
# This file should contain commands to set the command
# search path, plus other important environment variables.
# This file should not contain commands that produce
# output or assume the shell is attached to a tty.
#
# Global Order: zshenv, zprofile, zshrc, zlogin

if [[ -z "$PATH" || "$PATH" == "/bin:/usr/bin" ]]
then
        export PATH="/usr/local/bin:/usr/bin:/bin:/usr/games"
fi
echo OK
[[ -n "${key[Home]}"    ]]  && bindkey  "${key[Home]}"    beginning-of-line
.zshrc:2: bad substitution

編集3

バージョン: zsh 5.0.7(x86_64-pc-linux-gnu)

ベストアンサー1

zshこれは5.1で修正されたいくつかの以前のバージョンのバグでした。変更ログ:

2015-07-15 バートンシェーパー

  • 35799:Src / params.c:NO_EXECを使用すると、パラメータの下付き文字式を解析して中括弧のバランスを正しく調整しますが、下付き文字を適用しません。

後ろに報告される同じ日。

これらのバージョンでは、次のコマンドを使用してコピーできます。

$ zsh -nc '${a[1]}'
zsh:1: bad substitution

git bisectこの脆弱性は2011年に発生したことが知られています。連想配列に関連する同様の問題を修正提出中dfc26195c916d54163a3f0dd2eb159db2d974569、zsh-4.3.12バージョンから開始

より一般的にzsh -n(またはanyshell -n)のコードリント機能は、コードを実行しないため、やや制限的です。したがって、一部のコードが事前に実行される一部のコードによって評価される方法が異なる領域では、多くのことを行うことはできません。

たとえば、${a[1+]}配列では機能しませんが、ハッシュでは機能します。どちらがzsh -n文句を言わないかわからない。

また、次の誤検出を提供することもできます。

alias aslongas=while
aslongas whatever; do
  something
done

エイリアスをdo認識していないため、これらの驚きについて文句を言います。aslongaswhile

おすすめ記事