Store stdout in Bash Variable

Last modified: 
Thursday, April 2nd, 2015

Storing a string

CWD="$(pwd)"
echo $CWD
/home/hotpants

Storing a directory file listing

FILES=./*
echo $FILES
for f in $FILES; do
    echo $f
done

Outputs something like:

./Applications
./Desktop
./Documents
./Downloads
./Library
./Movies
./Music
./Pictures
./Public


The operator of this site makes no claims, promises, or guarantees of the accuracy, completeness, originality, uniqueness, or even general adequacy of the contents herein and expressly disclaims liability for errors and omissions in the contents of this website.