1.去除开头的一个或多个空格
#echo"forand12300a"|sed's/^[]*//g' #echo"forand12300a"|sed's/^[[:space:]]*//g' #var="forane12300a";echo$var
2.去除所有空格
echo"forand12300a"|tr-d""` var="forand12300a";echo${var///} echo"forand12300a"|sed's/^[[:space:]]*//g' echo"forand12300a"|awk'{gsub(//,"")}1'原文链接:https://www.f2er.com/bash/387852.html