Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: variable expansion inside string
- X-seq: zsh-users 24115
- From: Pier Paolo Grassi <pierpaolog@xxxxxxxxx>
- To: Peter Stephenson <p.stephenson@xxxxxxxxxxx>
- Subject: Re: variable expansion inside string
- Date: Tue, 30 Jul 2019 16:02:17 +0200
- Cc: Zsh-Users List <zsh-users@xxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ZNqeBrWucc+QC7XSo8tZeLi26MdGoAvHbCD0Ldt5JkQ=; b=OhCSqvDUQEwNErOnk1mZ8xT0zIKMQJ6GlTIvxF5vuktm/7k4qGTpd0ixrTDtwC3tGc 4frT0FCbcUko8EF4odVYH8m1RxcQUWk/foY/jli9JouRKr2FDSb0PpbUj17iZ8xHVdRf U5+xDSOTVAQYs8jjIOn/7yhlBNpV6nWPVY4Xco23EHRQiB+Z4PmTL2+42I+KB0l6DPDo zCtc7uMCgkRYDKFUNisYYUQztSFaQxUXoyQp/GWxhb2uZ0sOFi26LpknXPyeMtk0wrd2 z95ZSX5I7ZanyhooHA+dwk3aLzP+2zZjQXtgiXAuwocUSwiPoaZAAUN0T8XwhG3WIocT Qfng==
- In-reply-to: <1564492687.5815.4.camel@samsung.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- List-unsubscribe: <mailto:zsh-users-unsubscribe@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <CGME20190730123021epcas1p21671587b575bd82a2512bcb1fa091563@epcas1p2.samsung.com> <CAP+y1xAZiPn1B-GDPZw27fzBMdXSHbr+N3cgJBjOe_MeKG=0vw@mail.gmail.com> <1564492687.5815.4.camel@samsung.com>
thank you Peter, I made a mistake in the example code:
file="filename.txt"
a="*$file*"
should have been:
file="filename.txt"
a='*$file*'
with single quotes the behaviour is changed:
zsh -fc 'file= filename.txt; a="*$file*"; print "$a"'
gives:
*filename.txt*
instead with single quotes:
zsh -fc 'file= filename.txt; a=''*$file*''; print "$a"'
gives
*$file*
I would like the second example to somehow give the result of the first,
since I am trying to pass the string from another context where the
variable $file is not already defined
thanks
Pier Paolo Grassi
linkedin: https://www.linkedin.com/in/pier-paolo-grassi-19300217
founder: https://www.meetup.com/it-IT/Machine-Learning-TO
Il giorno mar 30 lug 2019 alle ore 15:19 Peter Stephenson <
p.stephenson@xxxxxxxxxxx> ha scritto:
> On Tue, 2019-07-30 at 14:28 +0200, Pier Paolo Grassi wrote:
> > Hello, is it possibile to do only variable expansion inside a string, eg:
> >
> > file="filename.txt"
> > a="*$file*"
>
> If you run zsh -f, you'll see that that's exactly what you normally get,
> just
> by running
>
> print "$a"
>
> --- no eval.
>
> My best guess is you have the option globsubst set and when you tried
> to print the result, you didn't use double quotes at that point, i.e.
> you had something like
>
> print $a
>
> and the *filename.text* got expanded at that point.
>
> So the original code is actually fine.
>
> pws
>
>
Messages sorted by:
Reverse Date,
Date,
Thread,
Author