From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 7509 invoked from network); 16 May 2020 21:28:41 -0000 Received: from ns1.primenet.com.au (HELO primenet.com.au) (203.24.36.2) by inbox.vuxu.org with ESMTPUTF8; 16 May 2020 21:28:41 -0000 Received: (qmail 5847 invoked by alias); 16 May 2020 21:28:34 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: List-Unsubscribe: X-Seq: 24844 Received: (qmail 16052 invoked by uid 1010); 16 May 2020 21:28:34 -0000 X-Qmail-Scanner-Diagnostics: from out1-smtp.messagingengine.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.102.3/25812. spamassassin: 3.4.4. Clear:RC:0(66.111.4.25):SA:0(-2.6/5.0):. Processed in 1.416652 secs); 16 May 2020 21:28:34 -0000 X-Envelope-From: d.s@daniel.shahaf.name X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: none (ns1.primenet.com.au: domain at daniel.shahaf.name does not designate permitted sender hosts) X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduhedruddttddgudeitdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvuffkjghfofggtgfgsehtqhdttdertdejnecuhfhrohhmpeffrghn ihgvlhcuufhhrghhrghfuceougdrshesuggrnhhivghlrdhshhgrhhgrfhdrnhgrmhgvqe enucggtffrrghtthgvrhhnpefhtdetfeehveeutdehuddtieefgeettedtjedtffehudei ieejleetteekudetheenucfkphepjeelrddukedtrdduvdejrddvvdejnecuvehluhhsth gvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepugdrshesuggrnhhivghl rdhshhgrhhgrfhdrnhgrmhgv X-ME-Proxy: Date: Sat, 16 May 2020 21:27:55 +0000 From: Daniel Shahaf To: TJ Luoma Cc: Zsh MailingList Subject: Re: Expanding a variable extracted from another file Message-ID: <20200516212755.28d7cd1e@tarpaulin.shahaf.local2> In-Reply-To: References: X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable TJ Luoma wrote on Sat, 16 May 2020 02:46 -0400: > Even if I do: >=20 > echo "$MYVAR" >=20 > I get the literal "$HOME" including double-quotes in the output. >=20 > 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. Variable values can be any string of bytes. If you can create a file that contains something, you can set a variable's value to that something. When you type =C2=ABecho "$HOME"=C2=BB on the command line, HOME is the nam= e of a variable whose value is =C2=AB/home/alice=C2=BB. However, it's also poss= ible to have a variable whose value is literally =C2=AB"$HOME"=C2=BB (7=C2=A0bytes)= . If you print that variable's value, you'll get those 7=C2=A0bytes back verbatim: . % s=3D'"$HOME"' % echo $s "$HOME" %=20 Values don't undergo variable expansion. If they did, stuff like . % s=3D'"$s"' % echo $s . would either crash or hang (depending on how precisely it's implemented). Flags such as ${(e)foo}, ${~foo}, and ${(P)foo} let you specifically ask for a word to be expanded. Even then, only one level of expansion happens: . % s=3D'$foo' % foo=3D'$bar' % bar=3D'This is bar'=20 % print -r -- ${s}=20 $foo % print -r -- ${(e)s}=20 $bar %=20 Whether any of these flags is the right tool for the job depends on the con= text. Cheers, Daniel P.S. =C2=ABecho $s=C2=BB does _not_ print $s verbatim for arbitrary values = of $s=C2=A0=E2=80=94 for example, backslash escape sequences would be expanded=C2=A0=E2=80=94 bu= t that doesn't matter in this case.