美文网首页
shell脚本去除前后空格

shell脚本去除前后空格

作者: 一路向后 | 来源:发表于2020-11-05 20:28 被阅读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

相关文章

网友评论

      本文标题:shell脚本去除前后空格

      本文链接:https://www.haomeiwen.com/subject/iobavktx.html