Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要将第一个匹配 $d1 的 substr 替换为 $d2 值。我写了这段代码:
i=${i/${d1}/${d2}}
它运行良好,但如果 $d1 或 $d2 包含空格符号则失败。我该如何解决?
使用双引号:
$ i="abc def ghi" $ d1="c d" $ d2="C D" $ i="${i/${d1}/${d2}}" $ echo "$i" abC Def ghi $