Eng*_*uad 1 linux ubuntu shell bash
假设我想替换某个字符串的第 n 个字母,我该怎么做?
我试过这样的事情,但它不正确:
#!/bin/bash
index= # let say 2
s='Hello'
echo ${s/$index/'a'} # This should print Healo
Run Code Online (Sandbox Code Playgroud)
有一个Advanced Bash-Scripting Guide向您展示了如何进行子字符串和连接。
让我们说:
#!/bin/bash
index=2
s=Hello
echo ${s:0:index-1}a${s:index}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8133 次 |
| 最近记录: |