Piet --

...and then Piet Delport said...
% On Fri, 14 Sep 2001 at 07:03:19 -0400, David T-G wrote:
% > % ---BEGIN---
% > % #!/bin/sh
% > ...
% > % pgp $* 2>$PGP_ERR 1>$PGP_OUT
...
% >   pgp ${1+"$@"} 2>$PGP_ERR 1>$PGP_OUT
% > 
% > and you're golden.
% 
% It's much more straightforward to use:
% 
%       pgp "$@" [...]
% 
% actually. :)

Oh, really?  Cool!

Actually, that looks familiar...  I wonder if I tried that under Solaris
and found it to not work, 'cuz I would have otherwise stripped down to
it.


% 
% > [BTW, I haven't *yet* found this in any shell documentation since I
% > saw it in a shell programming tip; can anyone provide me a pointer for
% > further research?]
% 
% I daresay you haven't been looking hard enough. :)

Well, there's always someone to say that.


% 
% Quoting FreeBSD's "man sh" [from the listing of special parameters]:
% |   @       Expands to the positional parameters, starting from one.
% |           When the expansion occurs within double-quotes, each
% |           positional parameter expands as a separate argument.  If
% |           there are no positional parameters, the expansion of @
% |           generates zero arguments, even when @ is double-quoted.
% |           What this basically means, for example, is if $1 is ``abc''
% |           and $2 is ``def ghi'', then "$@" expands to the two
% |           arguments:
% |                 "abc"   "def ghi"

Aha!  I don't use BSD (yet), so I don't have access to that, or at least
hadn't thought to search the web for a copy of the freebsd sh man page.
My linux system doesn't even have a man page for sh, preferring info or
whatever it is, and Solaris doesn't mention it at all.


% 
% As for further research, i generally got by on the sh and bash manpages
% up till now.  They're generally very concentrated in terms of info, and

Yep; I've learned a lot since first trying out "man man".


% take a while to sink in.  I find myself realizing new things all the
% time when i'm (re-)reading them. :-)

That's fun :-)


% 
% (Prominent example: just now while writing this mail, i saw for the
% first time how ${1+"$@"} works.  Ingenious approach, even if a bit

I see that "$@" protects argument expansion; what does the 1 mean?  And I
don't have a Solaris box handy to look in a man page to reference what +
means; I only use :- on a regular basis.


% redundant.  Most probably in the context of the tip you found it in it
% was a workaround for a shell that didn't handle a plain "$@" correctly?)

It was in a SysAdmin book and simply included in a shell script example
without any further comment.  Weird, eh?


% 
% -- 
% Piet Delport <[EMAIL PROTECTED]>
% Today's subliminal thought is:

Thanks for the info!


:-D
-- 
David T-G                      * It's easier to fight for one's principles
(play) [EMAIL PROTECTED] * than to live up to them. -- fortune cookie
(work) [EMAIL PROTECTED]
http://www.justpickone.org/davidtg/    Shpx gur Pbzzhavpngvbaf Qrprapl Npg!

PGP signature

Reply via email to