Pipe output to bash function

前端 未结 7 1061
故里飘歌
故里飘歌 2020-11-29 21:11

I have as simple function in a bash script and I would like to pipe stdout to it as an input.

jc_hms(){
  printf \"$1\"
}

I\'d like to use

7条回答
  •  生来不讨喜
    2020-11-29 21:40

    I like user.friendly's answer using the Bash built-in conditional unset substitution syntax. Here's a slight tweak to make his answer more generic, such as for cases with an indeterminate parameter count:

    function myfunc() {
        declare MY_INPUT=${*:-$(

提交回复
热议问题