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
#!/bin/bash
string=$1
if [[ "$1" == "" ]]
then
string=`cat /dev/stdin | head -n 1`
fi
echo ${string%%[\s]*##[\s]*}
$ ./trim " hello world "
hello world
$ echo " hello world " | ./trim
hello world
本文标题:shell脚本去除前后空格
本文链接:https://www.haomeiwen.com/subject/iobavktx.html
网友评论