Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Expanding a variable extracted from another file



Sorry for the vague subject,  I'm not 100% sure how to ask this.

Assume I have a plain text file "$HOME/MyReferenceDoc.txt" which has
these lines:

"$HOME/glue/sticks"
"$HOME/foo/bar"
"$HOME/work/files"

And I want to get the matching line which has '/foo/'

MYVAR=$(fgrep '/foo/' "$HOME/MyReferenceDoc.txt")

`$MYVAR` will now equal "$HOME/foo/bar" (with literal double-quotes
and a literal '$HOME')

Let's assume my actual home dir is '/home/james'

My question is: How can I tell zsh the it should expand the "$HOME" in
"$MYVAR" to "/home/james"?

Even if I do:

echo "$MYVAR"

I get the literal "$HOME" including double-quotes in the output.

I guess this must be some foundational Unix thing that I don't
understand properly, but all of my attempts to google it have come up
short because I'm not sure what to search for other than "expand
variable" but it's not quite that either.

Thanks

Tj



Messages sorted by: Reverse Date, Date, Thread, Author