gpt4 book ai didi

linux - 用空格替换\

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:04:04 27 4
gpt4 key购买 nike

我有 .sh 文件,其中一个变量是 admFilter=${10},我从 .bat< 接收这个变量的值 文件调用,很好,工作正常。当我执行 echo "$admFilter" 时,我看到了我的输出-:[Name]="Account\List\View"(这是完整的值)

我真正想要的是删除 "\" 并替换为 white 空格,所以最终输出将是 [Name]="Account List View "' ,然后将结果存储在另一个变量中,我不知道如何在此上使用 SED 命令(以前从未使用过),我还尝试了 tr 命令,但它结合了 [Name]="AccountListView"' 的字符串。任何人都可以帮助我如何获得所需的输出,并尽可能少地解释 sed 吗?谢谢

操作系统版本 -: SunOS 5.10 Generic_150400-52 sun4v sparc SUNW,T5240

最佳答案

假设 str 包含 [Name]="Account\List\View",以下变量扩展将所有 \ 替换为空格:

str='[Name]="Account\List\View"'
echo "${str//\\/ }"

来自 bash manual

${parameter/pattern/string}

The pattern is expanded to produce a pattern just as in filename 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 the nocasematch shell option (see the description of shopt in The Shopt Builtin) is enabled, the match is performed without regard to the case of alphabetic characters. 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.

关于linux - 用空格替换\,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48385439/

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