Pipe, standard input and command line arguments in Bash

前端 未结 4 882
轻奢々
轻奢々 2020-12-01 15:06

Consider:

command1 | command2

Is the output of command1 used as standard input of command2 or as command line arguments to command2?

<
4条回答
  •  时光取名叫无心
    2020-12-01 15:36

    Another form of redirection is process substitution.

    grep "hehe" <(cat test.sh)
    

    is equivalent to:

    grep "hehe" test.sh
    

    which both look at the contents of test.sh itself.

    While, as it has been noted, this command:

    grep "hehe" $(cat test.sh)
    

    looks for filenames in test.sh and uses them as arguments for grep. So if test.sh consists of:

    scriptone
    scripttwo
    

    then grep is going to look for "hehe" in the contents of each of those files.

提交回复
热议问题