How to read mutliline input from stdin into variable and how to print one out in shell(sh,bash)?

后端 未结 6 698
别那么骄傲
别那么骄傲 2020-12-23 11:09

What I want to do is the following:

  1. read in multiple line input from stdin into variable A
  2. make various operations on
6条回答
  •  我在风中等你
    2020-12-23 11:57

    Yes it works for me too. Thanks.

    myvar=`cat`
    

    is the same as

    myvar=`cat /dev/stdin`
    

    Well yes. From the bash man page:

    Enclosing characters in double quotes preserves the literal value of all characters within the quotes, with the exception of $, `, \, and, when history expansion is enabled, !. The characters $ and ` retain their special meaning within double quotes.

提交回复
热议问题