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

Re: Expanding a variable extracted from another file



On Fri, May 15, 2020 at 11:48 PM TJ Luoma <luomat@xxxxxxxxx> wrote:
>
> 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=${(f@M)$(<~/MyReferenceDoc.txt):#*/foo/*}

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

print -r -- ${(Qe)MYVAR}

Or leave out the Q if you want the double-quotes preserved.



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