/dev/stdin with herestring

前端 未结 4 1264
日久生厌
日久生厌 2020-12-18 03:19

I would like a Bash script that can take input from a file or stdin, much like grep, for example

$ cat          


        
4条回答
  •  北海茫月
    2020-12-18 03:43

    $ cat ts.sh 
    read b < "${1-/dev/stdin}"
    echo $b
    
    $ ./ts.sh <<< 'hello world'
    hello world
    

    No problem for me. I'm using bash 4.2.42 on Mac OS X.

提交回复
热议问题