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

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


This is working for me:

myvar=`cat`echo "$myvar"

The quotes around $myvar are important.


In Bash, there's an alternative way; man bash mentions:

The command substitution $(cat file) can be replaced by the equivalent but faster $(< file).

$ myVar=$(</dev/stdin)hellothis is test$ echo "$myVar"hellothis is test


tee does the job

#!/bin/bashmyVar=$(tee)