l_ccva
Last Updated: October 26, 2017
·
1.493K
· joseph
Default profile 6 normal

How to read a file into a variable in shell?

In cross-platform, lowest-common-denominator sh you use:

!/bin/sh

value=cat config.txt
echo "$value"

In bash or zsh, to read a whole file into a variable without invoking cat:

!/bin/bash

value=$(<config.txt)
echo "$value"

Say Thanks
Respond