请问如何理解以下bash脚本?

燕麦

请问以下bash脚本正在尝试做什么?

args=$(echo $@ |sed "s/^ *//;s/ *$//;s/ \{1,\}/ /g;s/-\{1,\} /-/g;s/ -/\t-/g")

谢谢!

hek2mgl

该脚本会修剪通过命令行传递给脚本的参数。(所有参数的数组都可以$@在外壳中使用寻址

修剪意味着,它将删除字符串中间的多余空格,并在每个参数的开头和结尾完全删除空格。您的代码将进一步用代替连字符前面的空格TAB

该命令所进行的转换详细如下:

s/^ *//          --> remove 0 or more spaces at the start of the string
s/ *$//          --> remove 0 or more spaces at the end of the string
/ \{1,\}/ /g     --> "melts" multiple spaces into one
s/-\{1,\} /-/g   --> Removes one or more white space after the hypen `-`
s/ -/\t-/g       --> Removes a space in front of a hypen by a TAB

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章