bash/shell的字符串trim实现
#!/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=
阅读(3) | 评论(0) | 转发(0) |
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=
相关热门文章
给主人留下些什么吧!~~
评论热议