zsh-users
 help / color / mirror / code / Atom feed
From: TJ Luoma <luomat@gmail.com>
To: Zsh MailingList <zsh-users@zsh.org>
Subject: Expanding a variable extracted from another file
Date: Sat, 16 May 2020 02:46:47 -0400	[thread overview]
Message-ID: <CADjGqHt8oF0W9AEU+j+yJHfOxxrVh-6HFP8ediAT0A_+qX9N8A@mail.gmail.com> (raw)

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

             reply	other threads:[~2020-05-16  6:48 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-16  6:46 TJ Luoma [this message]
2020-05-16  7:03 ` Bart Schaefer
2020-05-16  7:13   ` Roman Perepelitsa
2020-05-16 16:58     ` Bart Schaefer
2020-05-17 12:10   ` TJ Luoma
2020-05-16 21:27 ` Daniel Shahaf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CADjGqHt8oF0W9AEU+j+yJHfOxxrVh-6HFP8ediAT0A_+qX9N8A@mail.gmail.com \
    --to=luomat@gmail.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).