エイリアス do=... zsh 解析エラー

エイリアス do=... zsh 解析エラー

.zshrc私のホームディレクトリには次のファイルがあります。

# modify the prompt to contain git branch name if applicable
git_prompt_info() {
  current_branch=$(git current-branch 2> /dev/null)
  if [[ -n $current_branch ]]; then
    echo " %{$fg_bold[green]%}$current_branch%{$reset_color%}"
  fi
}
setopt promptsubst
export PS1='${SSH_CONNECTION+"%{$fg_bold[green]%}%n@%m:"}%{$fg_bold[blue]%}%c%{$reset_color%}$(git_prompt_info) %# '

# load our own completion functions
fpath=(~/.zsh/completion $fpath)

# completion
autoload -U compinit
compinit

# load custom executable functions
for function in ~/.zsh/functions/*; do
  source $function
done

# makes color constants available
autoload -U colors
colors

# enable colored output from ls, etc
export CLICOLOR=1

# history settings
setopt hist_ignore_all_dups inc_append_history
HISTFILE=~/.zhistory
HISTSIZE=4096
SAVEHIST=4096

# awesome cd movements from zshkit
setopt autocd autopushd pushdminus pushdsilent pushdtohome cdablevars
DIRSTACKSIZE=5

# Enable extended globbing
setopt extendedglob

# Allow [ or ] whereever you want
unsetopt nomatch

# vi mode
bindkey -v
bindkey "^F" vi-cmd-mode
bindkey jj vi-cmd-mode

# handy keybindings
bindkey "^A" beginning-of-line
bindkey "^E" end-of-line
bindkey "^R" history-incremental-search-backward
bindkey "^P" history-search-backward
bindkey "^Y" accept-and-hold
bindkey "^N" insert-last-word
bindkey -s "^T" "^[Isudo ^[A" # "t" for "toughguy"

# aliases
[[ -f ~/.aliases ]] && source ~/.aliases

# extra files in ~/.zsh/configs/pre , ~/.zsh/configs , and ~/.zsh/configs/post
# these are loaded first, second, and third, respectively.
_load_settings() {
  _dir="$1"
  if [ -d "$_dir" ]; then
    if [ -d "$_dir/pre" ]; then
      for config in "$_dir"/pre/**/*(N-.); do
        . $config
      done
    fi

    for config in "$_dir"/**/*(N-.); do
      case "$config" in
        "$_dir"/pre/*)
          :
          ;;
        "$_dir"/post/*)
          :
          ;;
        *)
          if [ -f $config ]; then
            . $config
          fi
          ;;
      esac
    done

    if [ -d "$_dir/post" ]; then
      for config in "$_dir"/post/**/*(N-.); do
        . $config
      done
    fi
  fi
}
_load_settings "$HOME/.zsh/configs"

# Local config
[[ -f ~/.zshrc.local ]] && source ~/.zshrc.local

残念ながら、端末を実行すると、次のエラーが発生します。

/home/steven/.zshrc:72: parse error near `fi'

問題は私のエイリアスファイルにあるようです。 2つのエイリアスファイルがあります。1. .aliases 2。.aliases.local

.aliasesロードする次のコマンドを含むロード済み.aliases.local

[[ -f ~/.aliases.local ]] && source ~/.aliases.local

私の.aliases.localファイルには2つのエイリアスがあります。

alias server='ssh -p xxx [email protected]'
alias do='ssh -L xxxx:127.0.0.1:xxxx -N -f -l user -p xxxx xx.xx.xxx.xxx'

これは、デフォルトで私のサーバー(最初のエイリアス)にSSHで接続し、VNCクライアントを使用してサーバーに接続できるようにセキュリティトンネルを設定するエイリアスです。

両方のエイリアスはうまく機能しますが、で定義すると、.aliases.localこのエラーは引き続き発生します。私は何が間違っていましたか?

ベストアンサー1

doシェルの予約語です。これはwhileandループ構文の一部ですfor。エイリアスとして定義すると、エイリアスは予約語よりも優先されます。したがって、エイリアス拡張後、シェルは次のことを確認します。

if [ -d "$_dir/pre" ]; then
  for config in "$_dir"/pre/**/*(N-.); ssh -L xxxx:127.0.0.1:xxxx -N -f -l user -p xxxx xx.xx.xxx.xxx
    . $config
  done
fi

fizshがセミコロンの後にtheの代わりにdoneまたはその欠如について文句を言う理由はわかりませんが、doそれでも有効な構文ではありません。

別名に別の名前を選択する必要があります。すべて避ける予約語

おすすめ記事