1.去除开头的一个或多个空格
#echo " forand 123 00 a " | sed 's/^[ ]*//g' #echo " forand 123 00 a " | sed 's/^[[:space:]]*//g' #var=" forane 123 00 a ";echo $var
2.去除所有空格
echo " forand 123 00 a " |tr -d " "` var=" forand 123 00 a ";echo ${var// /} echo " forand 123 00 a " | sed 's/^[[:space:]]*//g' echo " forand 123 00 a " | awk '{gsub(/ /,"")}1'
转载于:https://blog.51cto.com/853056088/2126068