How to trim whitespace from a Bash variable?

后端 未结 30 2636
星月不相逢
星月不相逢 2020-11-22 06:09

I have a shell script with this code:

var=`hg st -R \"$path\"`
if [ -n \"$var\" ]; then
    echo $var
fi

But the conditional code always ex

30条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-22 06:33

    This trims multiple spaces of the front and end

    whatever=${whatever%% *}

    whatever=${whatever#* }

提交回复
热议问题