且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Shell 脚本变量替换字符

更新时间:2023-12-05 15:05:10

对我有用.您需要使用单引号或转义美元符号,否则它们将从双引号字符串中删除:

Works for me. You'll need to use single quotes or escape the dollar signs, otherwise they are removed from the double-quoted string:

echo 'abcde$$$$$$$$fff$$gg' | tr '$' ' '
abcde        fff  gg

echo "abcde\$\$\$\$\$\$\$\$fff\$\$gg" | tr '$' ' '
abcde        fff  gg

echo abcde\$\$\$\$\$\$\$\$fff\$\$gg | tr '$' ' '
abcde        fff  gg

echo $'abcde$$$$$$$$fff$$gg' | tr '$' ' '
abcde        fff  gg