如何在bash shell中格式化字符串? [英] How to format a string in bash shell?
本文介绍了如何在bash shell中格式化字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在Linux中格式化变量
I am trying to format a variable in linux
str="Initial Value = 168"
echo "New Value=$(echo $str| cut -d '=' -f2);">>test.txt
我期望以下输出
Value = 168;
但是得到
Value = 168 ^M;
推荐答案
请勿在DOS或Windows上编辑bash脚本.您可以在bash脚本上运行dos2unix
.问题是Windows使用"\ r \ n"作为行分隔符,Linux使用"\ n".您还可以在Linux上的编辑器中手动删除"\ r"字符.
Don't edit your bash script on DOS or Windows. You can run dos2unix
on the bash script. The issue is that Windows uses "\r\n" as a line separator, Linux uses "\n". You can also manually remove the "\r" characters in an editor on Linux.
这篇关于如何在bash shell中格式化字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文