shell脚本去除前后空格
2020-11-05 本文已影响0人
一路向后
1.trim脚本源码
#!/bin/bash
string=$1
if [[ "$1" == "" ]]
then
string=`cat /dev/stdin | head -n 1`
fi
echo ${string%%[\s]*##[\s]*}
2.测试运行
$ ./trim " hello world "
hello world
$ echo " hello world " | ./trim
hello world