【问题标题】:What this line means in oh-my-zsh?这条线在 oh-my-zsh 中意味着什么?
【发布时间】:2013-04-13 19:27:07
【问题描述】:

在 oh-my-zsh 的 upgrade tool 中,我找到了这一行(第 2 行):

current_path=${current_path/ /\\ }

它做了什么?

另外,这条线在 mac 上也可以,但是在我的 ubuntu 服务器上它输出一个错误说:

.oh-my-zsh/tools/upgrade.sh: 2: .oh-my-zsh/tools/upgrade.sh: Bad substitution

【问题讨论】:

    标签: ubuntu sh zsh


    【解决方案1】:

    在 Ubuntu 上更新了它

    cd ~/.oh-my-zsh
    bash ~/.oh-my-zsh/tools/upgrade.sh
    

    【讨论】:

      【解决方案2】:

      请参阅手册中的parameter expansion

      ${name/pattern/repl}
      ${name//pattern/repl} 
      
      Replace the longest possible match of pattern in the expansion of parameter name by string repl. The first form replaces just the first occurrence, the second form all occurrences.
      

      本质上,上面所做的就是在${current_path} 的第一个空格前添加一个反斜杠。

      请注意,POSIX 未指定此语法(有关详细信息,请参阅 here),但所有当前的 bashkshzsh 版本都支持它。 Bad substitution 错误表明您没有在您认为自己执行的外壳下运行 upgrade.sh 工具(不支持它的外壳)。

      【讨论】:

        【解决方案3】:

        该行将反斜杠转义$current_path 变量中的第一个空格。并非所有 shell 都支持这种类型的替换,这就是它在 Ubuntu 上失败的原因。

        据我所知,这条线路没有充分的理由存在。如果在必要时转义空白,即使有效,该方法也是不够的。更糟糕的是,因为该变量的唯一使用是在双引号中使用反斜杠转义空格实际上会破坏它。

        【讨论】:

          【解决方案4】:

          我设法使用命令进行了更新:

          cd ~/.oh-my-zsh
          ggpull
          
          #or
          
          git pull origin master
          

          【讨论】:

          • gl = git pull(oh-my-zsh): cd ~/.oh-my-zsh && gl
          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-05-29
          • 2016-06-28
          • 1970-01-01
          • 2016-09-02
          相关资源
          最近更新 更多