* Re: Parameter expansion
1999-05-17 9:39 Parameter expansion Roland Jesse
@ 1999-05-17 9:23 ` Peter Stephenson
0 siblings, 0 replies; 13+ messages in thread
From: Peter Stephenson @ 1999-05-17 9:23 UTC (permalink / raw)
To: zsh-users
Roland Jesse wrote:
> But why do I do get the following than?
>
> % if [ ! ${+BLURB} ]; then
> then> echo "BLURB not set"
> then> else
> else> echo "BLURB set"
> else> fi
> BLURB set
> %
That's becuase
% if [ ! 0 ]; then print no; else print yes; fi
yes
% if [ ! 1 ]; then print no; else print yes; fi
yes
It's testing whether the string has length zero, which it doesn't. You
need arithmetical evaluation; change the [ to (( and the ] to )) and
everything should work.
--
Peter Stephenson <pws@ibmth.df.unipi.it> Tel: +39 050 844536
WWW: http://www.ifh.de/~pws/
Dipartimento di Fisica, Via Buonarroti 2, 56127 Pisa, Italy
^ permalink raw reply [flat|nested] 13+ messages in thread
* Parameter expansion
@ 1999-05-17 9:39 Roland Jesse
1999-05-17 9:23 ` Peter Stephenson
0 siblings, 1 reply; 13+ messages in thread
From: Roland Jesse @ 1999-05-17 9:39 UTC (permalink / raw)
To: zsh-users
The zsh manual says regarding to parameter expansion:
${+name}
If name is the name of a set parameter `1' is substituted, otherwise `0' is
substituted.
But why do I do get the following than?
% if [ ! ${+BLURB} ]; then
then> echo "BLURB not set"
then> else
else> echo "BLURB set"
else> fi
BLURB set
%
I was expecting the opposite. Curiously:
% export BLURB=foo
% if [ ! ${+BLURB} ]; then
echo "BLURB not set"
else
echo "BLURB set"
fi
BLURB set
%
Maybe the question should be: How do you check whether or not an
environment variable is set?
Comments are appreciated.
Roland
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Parameter Expansion
2017-08-14 0:07 ` Bart Schaefer
@ 2017-08-14 1:16 ` Clint Priest
0 siblings, 0 replies; 13+ messages in thread
From: Clint Priest @ 2017-08-14 1:16 UTC (permalink / raw)
To: Zsh Users
On 8/13/2017 7:07 PM, Bart Schaefer wrote:
>> FUNCS=( $SD/autoload/*(:t) )
Wow, it never dawned on me that I could just use it as a glob
qualifier. I'd be trying to do it with ${~..} and ${~~..} with no luck.
Thank you!
> Oh, and if you want something more complicated, the above is
> equivalent to using the "e" glob qualifier like so:
>
> $SD/autoload/*(e?'reply=( "$REPLY:t" )'?)
>
> So you can do any substitution tricks you want on $REPLY. Just
> remember that it will contain exactly one filename at a time.
I've read about but not yet played around with the e flag yet, but I've
heard of it. :)
Thanks again Bart!
--
-Clint
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Parameter Expansion
2017-08-13 23:51 ` Bart Schaefer
@ 2017-08-14 0:07 ` Bart Schaefer
2017-08-14 1:16 ` Clint Priest
0 siblings, 1 reply; 13+ messages in thread
From: Bart Schaefer @ 2017-08-14 0:07 UTC (permalink / raw)
To: Zsh Users
On Sun, Aug 13, 2017 at 4:51 PM, Bart Schaefer
<schaefer@brasslantern.com> wrote:
>
> FUNCS=( $SD/autoload/*(:t) )
Oh, and if you want something more complicated, the above is
equivalent to using the "e" glob qualifier like so:
$SD/autoload/*(e?'reply=( "$REPLY:t" )'?)
So you can do any substitution tricks you want on $REPLY. Just
remember that it will contain exactly one filename at a time.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Parameter Expansion
2017-08-13 22:58 Parameter Expansion Clint Priest
@ 2017-08-13 23:51 ` Bart Schaefer
2017-08-14 0:07 ` Bart Schaefer
0 siblings, 1 reply; 13+ messages in thread
From: Bart Schaefer @ 2017-08-13 23:51 UTC (permalink / raw)
To: Zsh Users
On Sun, Aug 13, 2017 at 3:58 PM, Clint Priest <cpriest@rxv.me> wrote:
> Having trouble getting nested parameter substitution working again, how can
> these two lines be correctly merged into a single line:
>
> FUNCS=( $SD/autoload/*);
> FUNCS=${(@)FUNCS:t};
You're mixing globbing with parameter substitution. Due to order of
operations (parameters before globs -- otherwise $SD/autoload/* would
not work) you can't do this via substitution.
Fortunately there are a lot of things you can do with globbing that
mimic parameter substitution, and :t happens to be one of them; you
can use it as a glob qualifier:
FUNCS=( $SD/autoload/*(:t) )
^ permalink raw reply [flat|nested] 13+ messages in thread
* Parameter Expansion
@ 2017-08-13 22:58 Clint Priest
2017-08-13 23:51 ` Bart Schaefer
0 siblings, 1 reply; 13+ messages in thread
From: Clint Priest @ 2017-08-13 22:58 UTC (permalink / raw)
To: Zsh Users
[-- Attachment #1: Type: text/plain, Size: 396 bytes --]
Having trouble getting nested parameter substitution working again, how
can these two lines be correctly merged into a single line:
FUNCS=( $SD/autoload/*);
FUNCS=${(@)FUNCS:t};
Assume for arguments sake that SD is a working directory with an
autoload directory and autoload has one file in it (named pv).
The above two lines together properly produce ( pv ).
Thanks,
--
-Clint
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Parameter expansion
1999-04-01 6:20 ` Rob Hooft
1999-04-01 7:30 ` Geoff Wing
@ 1999-04-01 7:33 ` Bart Schaefer
1 sibling, 0 replies; 13+ messages in thread
From: Bart Schaefer @ 1999-04-01 7:33 UTC (permalink / raw)
To: Rob Hooft, zsh-users
On Apr 1, 8:20am, Rob Hooft wrote:
} Subject: Re: Parameter expansion
}
} I understand this is a zsh mailinglist, but I find the shell-independent
}
} xargs zip backup.zip < index.txt
}
} more readable, and it gracefully handles the case where index.txt is too
} long for the command line....
Zsh can handle VERY long command lines ... much longer than required to
hold the number of arguments xargs will pass to a single command by
default. Does
zip backup.zip file1 file2 ... fileN
zip backup.zip fileN+1 fileN+2 ... file2N
really do the right thing? Because that's roughly what'll get executed
if there are enough lines in index.txt. Even if zip does the right thing
in that case, "xargs tar zcf backup.tar" is a recipe for disaster.
Finally, the whole point of the question was that index.txt contains
file _patterns_, not file names; xargs, by design, won't expand file
patterns, so your solution would fail completely.
--
Bart Schaefer Brass Lantern Enterprises
http://www.well.com/user/barts http://www.brasslantern.com
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Parameter expansion
1999-04-01 6:20 ` Rob Hooft
@ 1999-04-01 7:30 ` Geoff Wing
1999-04-01 7:33 ` Bart Schaefer
1 sibling, 0 replies; 13+ messages in thread
From: Geoff Wing @ 1999-04-01 7:30 UTC (permalink / raw)
To: zsh-users
Rob Hooft <r.hooft@euromail.net> typed:
:>>>>> "BS" == Bart Schaefer <schaefer@brasslantern.com> writes:
: BS> On Mar 31, 6:04pm, Mircea Damian wrote: } Subject: Re: Parameter
: BS> expansion } } On Wed, Mar 31, 1999 at 02:54:01PM +0000, Geoff
: BS> Wing wrote: } > Mircea Damian <dmircea@kappa.ro> typed: } > :zip
: BS> backup.zip $(<index.txt) } > } > zip backup.zip $(eval echo
: BS> $(<index.txt))
: BS> eval zip backup.zip $(<index.txt)
: BS> zip backup.zip ${~$(<index.txt)}
:I understand this is a zsh mailinglist, but I find the shell-independent
: xargs zip backup.zip < index.txt
:more readable, and it gracefully handles the case where index.txt is too
:long for the command line....
Yep, though Bart's example ``zip backup.zip ${~$(<index.txt)}'' handles
the case where names have spaces in them.
Regards,
--
Geoff Wing <gcw@pobox.com> Mobile : (Australia) 0412 162 441
Work URL: http://www.primenet.com.au/ Ego URL: http://pobox.com/~gcw/
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Parameter expansion
1999-03-31 15:51 ` Bart Schaefer
@ 1999-04-01 6:20 ` Rob Hooft
1999-04-01 7:30 ` Geoff Wing
1999-04-01 7:33 ` Bart Schaefer
0 siblings, 2 replies; 13+ messages in thread
From: Rob Hooft @ 1999-04-01 6:20 UTC (permalink / raw)
To: zsh-users
>>>>> "BS" == Bart Schaefer <schaefer@brasslantern.com> writes:
BS> On Mar 31, 6:04pm, Mircea Damian wrote: } Subject: Re: Parameter
BS> expansion } } On Wed, Mar 31, 1999 at 02:54:01PM +0000, Geoff
BS> Wing wrote: } > Mircea Damian <dmircea@kappa.ro> typed: } > :zip
BS> backup.zip $(<index.txt) } > } > zip backup.zip $(eval echo
BS> $(<index.txt))
BS> eval zip backup.zip $(<index.txt)
BS> zip backup.zip ${~$(<index.txt)}
I understand this is a zsh mailinglist, but I find the shell-independent
xargs zip backup.zip < index.txt
more readable, and it gracefully handles the case where index.txt is too
long for the command line....
--
===== R.Hooft@EuroMail.net http://www.xs4all.nl/~hooft/rob/ =====
===== R&D, Nonius BV, Delft http://www.nonius.nl/ =====
===== PGPid 0xFA19277D ========================== Use Linux! =========
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Parameter expansion
1999-03-31 15:04 ` Mircea Damian
@ 1999-03-31 15:51 ` Bart Schaefer
1999-04-01 6:20 ` Rob Hooft
0 siblings, 1 reply; 13+ messages in thread
From: Bart Schaefer @ 1999-03-31 15:51 UTC (permalink / raw)
To: Mircea Damian, Geoff Wing; +Cc: zsh-users
On Mar 31, 6:04pm, Mircea Damian wrote:
} Subject: Re: Parameter expansion
}
} On Wed, Mar 31, 1999 at 02:54:01PM +0000, Geoff Wing wrote:
} > Mircea Damian <dmircea@kappa.ro> typed:
} > :zip backup.zip $(<index.txt)
} >
} > zip backup.zip $(eval echo $(<index.txt))
eval zip backup.zip $(<index.txt)
zip backup.zip ${~$(<index.txt)}
--
Bart Schaefer Brass Lantern Enterprises
http://www.well.com/user/barts http://www.brasslantern.com
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Parameter expansion
1999-03-31 14:54 ` Geoff Wing
@ 1999-03-31 15:04 ` Mircea Damian
1999-03-31 15:51 ` Bart Schaefer
0 siblings, 1 reply; 13+ messages in thread
From: Mircea Damian @ 1999-03-31 15:04 UTC (permalink / raw)
To: Geoff Wing; +Cc: zsh-users
On Wed, Mar 31, 1999 at 02:54:01PM +0000, Geoff Wing wrote:
> Mircea Damian <dmircea@kappa.ro> typed:
> :I want to create an archive for the files that are matched by the contents of
> :index.txt
> :I tried in dir/ to run the command:
> :zip backup.zip $(<index.txt)
>
> zip backup.zip $(eval echo $(<index.txt))
Yess.. of course. And it's obvious! Thanks a lot!
--
Mircea Damian
Network Manager
dmircea@roedu.net, dmircea@lbi.ro, dmircea@kappa.ro
MD65-RIPE, MD2225, MD1-6BONE
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Parameter expansion
1999-03-31 14:35 Parameter expansion Mircea Damian
@ 1999-03-31 14:54 ` Geoff Wing
1999-03-31 15:04 ` Mircea Damian
0 siblings, 1 reply; 13+ messages in thread
From: Geoff Wing @ 1999-03-31 14:54 UTC (permalink / raw)
To: zsh-users
Mircea Damian <dmircea@kappa.ro> typed:
:I want to create an archive for the files that are matched by the contents of
:index.txt
:I tried in dir/ to run the command:
:zip backup.zip $(<index.txt)
zip backup.zip $(eval echo $(<index.txt))
:but that didn't worked because the file* another* weren't expanded. How do
:I tell him(zsh 3.1.5) to expand the result of $(<index.txt)?
--
Geoff Wing <gcw@pobox.com> Mobile : (Australia) 0412 162 441
Work URL: http://www.primenet.com.au/ Ego URL: http://pobox.com/~gcw/
^ permalink raw reply [flat|nested] 13+ messages in thread
* Parameter expansion
@ 1999-03-31 14:35 Mircea Damian
1999-03-31 14:54 ` Geoff Wing
0 siblings, 1 reply; 13+ messages in thread
From: Mircea Damian @ 1999-03-31 14:35 UTC (permalink / raw)
To: zsh-users
Hello,
I need some help here and maybe someone of you can help.
Supposing that I have this directory structure:
dir -+- backup -+- file.1
| +- file.2
| +- anotherfile.txt
| +- dont_backup
+- index.txt
And index.txt is:
file*
another*
I want to create an archive for the files that are matched by the contents of
index.txt
I tried in dir/ to run the command:
zip backup.zip $(<index.txt)
but that didn't worked because the file* another* weren't expanded. How do
I tell him(zsh 3.1.5) to expand the result of $(<index.txt)?
Thanks!
--
Mircea Damian
Network Manager
dmircea@roedu.net, dmircea@lbi.ro, dmircea@kappa.ro
MD65-RIPE, MD2225, MD1-6BONE
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2017-08-14 1:16 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-05-17 9:39 Parameter expansion Roland Jesse
1999-05-17 9:23 ` Peter Stephenson
-- strict thread matches above, loose matches on Subject: below --
2017-08-13 22:58 Parameter Expansion Clint Priest
2017-08-13 23:51 ` Bart Schaefer
2017-08-14 0:07 ` Bart Schaefer
2017-08-14 1:16 ` Clint Priest
1999-03-31 14:35 Parameter expansion Mircea Damian
1999-03-31 14:54 ` Geoff Wing
1999-03-31 15:04 ` Mircea Damian
1999-03-31 15:51 ` Bart Schaefer
1999-04-01 6:20 ` Rob Hooft
1999-04-01 7:30 ` Geoff Wing
1999-04-01 7:33 ` Bart Schaefer
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).