Writing a BASH Script to Read from STDIN to a Variable

Let’s say you have some program that is generating output to STDOUT and you want to write a script to read that output from STDIN and use it as a variable in your script.

To do so:

#!/bin/bash

SOME_VAR=$(cat)
echo "SOME_VAR = $SOME_VAR"

Continue reading “Writing a BASH Script to Read from STDIN to a Variable”