这条线在oh-my-zsh中意味着什么?

时间:2013-04-20 13:34:31

标签: ubuntu sh zsh

在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

4 个答案:

答案 0 :(得分:11)

使用

在Ubuntu上更新了它
cd ~/.oh-my-zsh
bash ~/.oh-my-zsh/tools/upgrade.sh

答案 1 :(得分: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错误表明您没有在您认为自己执行的shell下运行upgrade.sh工具(不支持它)。

答案 2 :(得分:1)

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

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

答案 3 :(得分:1)

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

cd ~/.oh-my-zsh
ggpull

#or

git pull origin master
相关问题