简体   繁体   English

这个bash参数扩展语法的含义是什么?

[英]What's the meaning of this bash parameter expansion syntax?

In the golang GOPATH documentation it instructs you to add the following to your bash PATH: golang GOPATH文档中,它指示您将以下内容添加到bash PATH中:

${GOPATH//://bin:}/bin

What does the //://bin: mean here? //://bin:是什么意思?

$GOPATH appears to evaluate to the same value as ${GOPATH//://bin:} $GOPATH计算$GOPATH似乎与${GOPATH//://bin:}

My first guess was that this somehow expands into all subdirectories of $GOPATH that have a /bin subdirectory, but this does not appear to be the case. 我的第一个猜测是,它以某种方式扩展到了具有/bin子目录的$GOPATH所有子目录,但事实并非如此。 I added some subdirectories to my $GOPATH with a /bin dir, and the above expression does not include them. 我用/bin目录向$ GOPATH添加了一些子目录,上面的表达式不包括它们。

I dug into my manpage for bash and didn't see any hints. 我浏览了联机帮助中的bash,但没有看到任何提示。

man bash says under PARAMETER EXPANSION: man bash在参数扩展下说:

${parameter/pattern/string}

Pattern substitution. 模式替换。 The pattern is expanded to produce a pattern just as in pathname expansion. 与路径名扩展一样,扩展模式以产生模式。 Parameter is expanded and the longest match of pattern against its value is replaced with string. 扩展参数,并将模式与其值的最长匹配项替换为字符串。 If pattern begins with /, all matches of pattern are replaced with string. 如果pattern以/开头,则pattern的所有匹配项都将替换为字符串。 Normally only the first match is replaced. 通常只替换第一个比赛。

eg 例如

$ GOPATH=a:b:c
$ echo ${GOPATH//://bin:}
a/bin:b/bin:c

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM