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

后端 未结 6 699
别那么骄傲
别那么骄傲 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条回答
  •  猫巷女王i
    2020-12-23 11:54

    If you do care about preserving trailing newlines at the end of the output, use this:

    myVar=$(cat; echo x)
    myVar=${myVar%x}
    printf %s "$myVar"
    

    This uses the trick from here.

提交回复
热议问题