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"
Written by tien nguyen
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Bash shell
Authors
joseph
87.06K
Related Tags
#bash shell
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#