假设我想replace一些string的第n个字母,我该怎么做?
我尝试了这样的事情,但这是不正确的:
#!/bin/bash index= # let say 2 s='Hello' echo ${s/$index/'a'} # This should print Healo
有一个高级Bash脚本指南 ,告诉你如何做子串和连接。
我们说:
#!/bin/bash index=2 s=Hello echo ${s:0:index-1}a${s:index}
sed另一个解决scheme:
$ echo "hello" | sed 's/\(.\{2\}\)./\1a/'