/dev/stdin with herestring

前端 未结 4 1285
日久生厌
日久生厌 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:24

    bash parses some file names (like /dev/stdin) specially, so that they are recognized even if they are not actually present in the file system. If your script doesn't have #!/bin/bash at the top, and /dev/stdin isn't in your file system, your script may be run using /bin/sh, which would expect /dev/stdin to actually be a file.

    (This should, perhaps, not be an answer, but rather a comment to Austin's answer.)

提交回复
热议问题