替换所有
echo ${MESSAGE//e/E}
替换第一个
echo ${MESSAGE/e/E}
Code:
$ MESSAGE="Develop a passion for learning. If you do, you will never cease to grow."
$ echo ${MESSAGE}
Develop a passion for learning. If you do, you will never cease to grow.
# Replace part of the text.
# Replace "passion" with "desire":
$ echo ${MESSAGE/passion/desire}
Develop a desire for learning. If you do, you will never cease to grow.
# Remove part of the text.
# Here, remove "passion":
$ echo ${MESSAGE/passion}
Develop a for learning. If you do, you will never cease to grow.
# Replace the first match in the text.
# Here, "e" becomes "E":
$ echo ${MESSAGE/e/E}
DEvelop a passion for learning. If you do, you will never cease to grow.
$
# Replace all matches in the text, by adding an extra slash (/).
# Here, all "e" become "E":
$ echo ${MESSAGE//e/E}
DEvElop a passion for lEarning. If you do, you will nEvEr cEasE to grow.
替换日期
2020-11-16 2020/11/16
$ echo ${MESSAGE//e/E}
$ date_str='2020-11-16'
$ echo ${date_str//-/\}
2020/11/16
参考