#!/bin/sh
trim()
{
trimmed=$1
trimmed=${trimmed%% }
trimmed=${trimmed## }
echo $trimmed
}
测试:
a=” x x ”
b=” b b”
c=”c c ”
echo “=$a=”
echo “=$b=”
echo “=$c=”
a=$(trim $a)
b=$(trim $b)
c=$(trim $c)
echo “=$a=”
echo “=$b=”
echo “=$c=”
输出:
= x x =
= b b=
=c c =
=x=
=b=
=c=