gpt4 book ai didi

bash - Bash 参数扩展中的 `//` 是什么意思?

转载 作者:行者123 更新时间:2023-11-29 09:04:32 25 4
gpt4 key购买 nike

//,/ 在此命令中是什么意思?

echo ${foo//,/}

最佳答案

来自 bash(1) 手册页(http://linux.die.net/man/1/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. Normally only the first match is replaced. If pattern begins with #, it must match at the beginning of the expanded value of parameter. If pattern begins with %, it must match at the end of the expanded value of parameter. If string is null, matches of pattern are deleted and the / following pattern may be omitted. If parameter is @ or *, the substitution operation is applied to each positional parameter in turn, and the expansion is the resultant list. If parameter is an array variable subscripted with @ or *, the substitution operation is applied to each member of the array in turn, and the expansion is the resultant list.

也就是说,${something//, 被扩展为 $something,所有出现的 , 都被移除。

关于bash - Bash 参数扩展中的 `//` 是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34789149/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com