cat file | … vs … <file

前端 未结 7 2056
北荒
北荒 2020-12-16 13:59

Is there a case of ... or context where cat file | ... behaves differently than ... ?

7条回答
  •  忘掉有多难
    2020-12-16 14:18

    Pipes cause a subshell to be invoked for the command on the right. This interferes with environment variables.

    cat foo | while read line
    do
      ...
    done
    echo "$line"
    

    versus

    while read line
    do
      ...
    done < foo
    echo "$line"
    

提交回复
热议问题