Pipe output to bash function

前端 未结 7 1051
故里飘歌
故里飘歌 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:41

    You can't pipe stuff directly to a bash function like that, however you can use read to pull it in instead:

    jc_hms() {
      while read -r data; do
          printf "%s" "$data"
      done
    }
    

    should be what you want

提交回复
热议问题