Capture output from command into variable retaining new lines
问题 I have two scripts; parentScript.sh and childScript.sh . I want to be able to call childScript.sh inside parentScript.sh and return the errors that occur within at any stage. i.e. an error found within childScript.sh looks like: echo "ERROR: Feed file missing for $siteTag" >&2 I know how to return the error out back towards the parent shell. But I have a feeling it is being tampered with, I can no longer printf the result to a nice looking variable. i.e. error+="$( { ./childScript.sh | sed 's