regex – bash控制语句//,/ double forward slash

在这个例子中//,/是什么意思?

for SCHEMA_ONLY_DB in ${SCHEMA_ONLY_LIST//,/}
do
    SCHEMA_ONLY_CLAUSE="$SCHEMA_ONLY_CLAUSE or datname ~ '$SCHEMA_ONLY_DB'"
done

SCHEMA_ONLY_LIST="mydb1,mydb2,mydb3,mydb4"
SCHEMA_ONLY_DB=mydb1

$SCHEMA_ONLY_CLAUSE现已填充:

echo $SCHEMA_ONLY_CLAUSE
or datname ~ 'mydb1' or datname ~ 'mydb2' or datname ~ 'mydb3'

解决方法

从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,其中包含所有出现的内容,已删除.

相关文章

用的openwrt路由器,家里宽带申请了动态公网ip,为了方便把2...
#!/bin/bashcommand1&command2&wait从Shell脚本并行...
1.先查出MAMP下面集成的PHP版本cd/Applications/MAMP/bin/ph...
1、先输入locale-a,查看一下现在已安装的语言2、若不存在如...
BashPerlTclsyntaxdiff1.进制数表示Languagebinaryoctalhexa...
正常安装了k8s后,使用kubect工具后接的命令不能直接tab补全...