Re: OT: Shell scripting [was: Re: Fix for PGP copyright thing...]

2001-09-17 Thread Paul de Weerd

On Sun, Sep 16, 2001 at 04:42:10PM -0700, Will Yardley wrote:
| David T-G wrote:
|  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.
| 
| most linux distributions (all??) come with /bin/sh linked to bash.
| however bash is supposed to be able to do anything the bourne shell can
| do, no?  if that's the case you should be able to do the same thing,
| probably in a pretty much identical way.
| 
| it seems kind of silly to me - i rarely use the bourne shell but i like
| the fact that it's there in bsd systems (and that if i specify /bin/sh
| that's exactly what i'm getting).
| 
| try checking the bash man pages.

Actually bash has a 'sh' mode of operation, where if you start bash
from /bin/sh, it will function quite different from /bin/bash. It
even has an init mode (try booting linux with 'init=/bin/sh' on the
LILO prompt (or from whatever linux loader you use)) but I've never
found any differences with normal bash (other then the PS1 prompt).

From bash(1):
If  bash is invoked with the name sh, it tries to mimic the
startup behavior of historical versions of sh as closely as
possible, while conforming to  the  POSIX  standard  as well.

Paul 'WEiRD' de Weerd



Re: OT: Shell scripting [was: Re: Fix for PGP copyright thing...]

2001-09-17 Thread David T-G

Will --

...and then Will Yardley said...
% David T-G wrote:
%  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.
% 
% most linux distributions (all??) come with /bin/sh linked to bash.

Yep.


% however bash is supposed to be able to do anything the bourne shell can

Yes, and then some.


% do, no?  if that's the case you should be able to do the same thing,
% probably in a pretty much identical way.

Exactly.


% 
% it seems kind of silly to me - i rarely use the bourne shell but i like
% the fact that it's there in bsd systems (and that if i specify /bin/sh
% that's exactly what i'm getting).

No, it's not silly at all -- /bin/sh is one of the things that can be
found on any unix system, and shell scripts are so basically fundamental
that they will be necessary everywhere and you might even be expected to
take your own scripts and move them from box to box.

Doing away with /bin/sh would be a Very Bad Thing.


% 
% try checking the bash man pages.

I did; I don't have those, either :-(


% 
% w

Thanks a bunch!


:-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


Re: OT: Shell scripting [was: Re: Fix for PGP copyright thing...]

2001-09-17 Thread David T-G

David --

...and then David Champion said...
% On 2001.09.16, in [EMAIL PROTECTED],
%   David T-G [EMAIL PROTECTED] wrote:
%  
%  % Quoting FreeBSD's man sh [from the listing of special parameters]:
...
%  Aha!  I don't use BSD (yet), so I don't have access to that, or at least
...
%  whatever it is, and Solaris doesn't mention it at all.
% 
% Solaris does, just differently. The section on ${parameter} says first
% that if the parameter is * or @, all positional parameters are

Hmmm -- as though $@ and $* are equivalent...


% substituted. Later, in the section on quoting, it says that if $@
% is encased in double-quotes, then the pos'nal params are quoted, and
% separated by unquoted spaces. Searching the manual for @ shows this.

It sure should.  I wonder how I missed it.


% 
%  % 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.
% 
% From Solaris's sh(1):
%  ${parameter:+word}
%If parameter is set and is non-null, substitute  word;
%otherwise substitute nothing.
%  ...
%  If the colon (:) is omitted from the above expressions,  the
%  shell only checks whether parameter is set or not.
% 
% :+ is the flipside of :- -- :- substitutes if parameter doesn't
% have a non-null value, but :+ substitutes if it does.

Ah, that makes sense.  Of course, I dunno when I'd otherwise want to
substitute if the variable is set and not when it's not, but maybe that's
simply why it's there :-)


% 
% So ${1+$@} means to substitute all args, quoted, if there is a first
% argument (null or not). It's equivalent to $@ alone on most systems
% I've seen. ${1:+$@} is not equivalent.

I get that, but it seems as though, since the colon is omitted, it should
really do nothing, no?


% 
% 
%  % 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's possible that some shells might issue an error evaluating $@ if
% no arguments are present. csh(1) does this by design when evaluating
% any variable. This is the kind of behavior I wouldn't be surprised to

Right...


% see in older versions of AIX, for example; it's sometimes been fairly
% strict in its response to undefined conditions. Most systems substitute
% nothing if there are no args. UNIX98 requires this, but I can't say with

That makes sense and is what I'd expect from a shell that can handle $VAR
being empty (like csh cannot except for the $?VAR test).


% certainty that prior versions of this standards family require anything
% particular, so ${1+$@} might well be needed for backward compatibility
% to POSIX or XPG or something. I don't know where to find these standards
% online; the Open Group no longer offer previous editions to SUS.

Ah, well.


% 
% -- 
%  -D.  [EMAIL PROTECTED]NSITUniversity of Chicago

Thanks for the very informative reply!


:-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


Re: OT: Shell scripting [was: Re: Fix for PGP copyright thing...]

2001-09-17 Thread Will Yardley

David T-G wrote:
  it seems kind of silly to me - i rarely use the bourne shell but i
  like the fact that it's there in bsd systems (and that if i specify
  /bin/sh that's exactly what i'm getting).
 
 No, it's not silly at all -- /bin/sh is one of the things that can be
 found on any unix system, and shell scripts are so basically
 fundamental that they will be necessary everywhere and you might even
 be expected to take your own scripts and move them from box to box.
 
 Doing away with /bin/sh would be a Very Bad Thing.

agreed.  i meant it was kind of silly that linux uses bash instead of
the bourne shell.  i was certainly not trying to suggest that we abolish
the bourne shell!

w

-- 
Sintax error in config file! (line 378)
aborted!

GPG Public Key:
http://infinitejazz.net/will/pgp/



Re: OT: Shell scripting [was: Re: Fix for PGP copyright thing...]

2001-09-17 Thread David T-G

Will --

...and then Will Yardley said...
% David T-G wrote:
%   it seems kind of silly to me - i rarely use the bourne shell but i
...
%  
%  No, it's not silly at all -- /bin/sh is one of the things that can be
...
%  Doing away with /bin/sh would be a Very Bad Thing.
% 
% agreed.  i meant it was kind of silly that linux uses bash instead of
% the bourne shell.  i was certainly not trying to suggest that we abolish
% the bourne shell!

Ah :-)  Well, you can't use the Bourne shell without proper licensing,
and GNU/Linux is all about free stuff.  There's a written-from-scratch
PDksh public domain ksh out there, but bash is the only ready-today free
sh clone (and then some :-) out there.


% 
% w


:-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


Re: OT: Shell scripting [was: Re: Fix for PGP copyright thing...]

2001-09-17 Thread Will Yardley

David T-G wrote:
 Ah :-)  Well, you can't use the Bourne shell without proper licensing,
 and GNU/Linux is all about free stuff.  There's a written-from-scratch
 PDksh public domain ksh out there, but bash is the only ready-today
 free sh clone (and then some :-) out there.

ahh forgot about that. i didn't realize the freebsd version was ash and
not the real bourne shell (at least looking through the source code it
looks like it's 'ash').  ash is on some linux machines as well (debian
i'm pretty sure).

isn't the korn shell open source now, or is it just free as in beer?

in any event i guess we're getting _really_ off topic now :

w

-- 
Sintax error in config file! (line 378)
aborted!

GPG Public Key:
http://infinitejazz.net/will/pgp/



Re: OT: Shell scripting [was: Re: Fix for PGP copyright thing...]

2001-09-17 Thread Piet Delport


--da9oBGf5DLtF9ehv
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Mon, 17 Sep 2001 at 17:19:26 -0400, David T-G wrote:
 Will --
=20
 ...and then Will Yardley said...
 % David T-G wrote:
 %   it seems kind of silly to me - i rarely use the bourne shell but i
 ...
 % =20
 %  No, it's not silly at all -- /bin/sh is one of the things that can be
 ...
 %  Doing away with /bin/sh would be a Very Bad Thing.
 %=20
 % agreed.  i meant it was kind of silly that linux uses bash instead of
 % the bourne shell.  i was certainly not trying to suggest that we abolish
 % the bourne shell!
=20
 Ah :-)  Well, you can't use the Bourne shell without proper licensing,
 and GNU/Linux is all about free stuff.  There's a written-from-scratch
 PDksh public domain ksh out there, but bash is the only ready-today free
 sh clone (and then some :-) out there.

Ahem.

This may (or may not) be true of the original Bourne shell, but the *BSD
/bin/sh is very real, and is even more free than bash in terms of
licensing.  :-)

And then there's still zsh, sash, and many other variations probably.

(This is getting very off-topic for mutt-users, we should probably take
it off-list.)

--=20
Piet Delport [EMAIL PROTECTED]
Today's subliminal thought is:

--da9oBGf5DLtF9ehv
Content-Type: application/pgp-signature
Content-Disposition: inline

-BEGIN PGP SIGNATURE-
Version: GnuPG v1.0.6 (FreeBSD)

iD8DBQE7ppU7zRUP82sZFCcRAqc6AJ4s/rPd1sW8aCMed5UqKUSrmascVACdHdrn
2pcS/2Y6fMG/MULWNCnQT+M=
=GMOP
-END PGP SIGNATURE-

--da9oBGf5DLtF9ehv--



Re: OT: Shell scripting [was: Re: Fix for PGP copyright thing...]

2001-09-16 Thread David T-G

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


Re: OT: Shell scripting [was: Re: Fix for PGP copyright thing...]

2001-09-16 Thread David Champion

On 2001.09.16, in [EMAIL PROTECTED],
David T-G [EMAIL PROTECTED] wrote:
 
 % 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
 
 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.

Solaris does, just differently. The section on ${parameter} says first
that if the parameter is * or @, all positional parameters are
substituted. Later, in the section on quoting, it says that if $@
is encased in double-quotes, then the pos'nal params are quoted, and
separated by unquoted spaces. Searching the manual for @ shows this.


 % (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.

From Solaris's sh(1):
 ${parameter:+word}
   If parameter is set and is non-null, substitute  word;
   otherwise substitute nothing.
 ...
 If the colon (:) is omitted from the above expressions,  the
 shell only checks whether parameter is set or not.

:+ is the flipside of :- -- :- substitutes if parameter doesn't
have a non-null value, but :+ substitutes if it does.

So ${1+$@} means to substitute all args, quoted, if there is a first
argument (null or not). It's equivalent to $@ alone on most systems
I've seen. ${1:+$@} is not equivalent.


 % 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's possible that some shells might issue an error evaluating $@ if
no arguments are present. csh(1) does this by design when evaluating
any variable. This is the kind of behavior I wouldn't be surprised to
see in older versions of AIX, for example; it's sometimes been fairly
strict in its response to undefined conditions. Most systems substitute
nothing if there are no args. UNIX98 requires this, but I can't say with
certainty that prior versions of this standards family require anything
particular, so ${1+$@} might well be needed for backward compatibility
to POSIX or XPG or something. I don't know where to find these standards
online; the Open Group no longer offer previous editions to SUS.

-- 
 -D.[EMAIL PROTECTED]NSITUniversity of Chicago



OT: Shell scripting [was: Re: Fix for PGP copyright thing...]

2001-09-15 Thread Piet Delport


--a2FkP9tdjPU2nyhF
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Fri, 14 Sep 2001 at 07:03:19 -0400, David T-G wrote:
 % ---BEGIN---
 % #!/bin/sh
 ...
 % pgp $* 2$PGP_ERR 1$PGP_OUT
=20
 BTW, you might want to modify your script to protect any arguments with
 embedded spaces.  Change the line above to
=20
   pgp ${1+$@} 2$PGP_ERR 1$PGP_OUT
=20
 and you're golden.

It's much more straightforward to use:

pgp $@ [...]

actually. :)

 [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. :)

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

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
take a while to sink in.  I find myself realizing new things all the
time when i'm (re-)reading them. :-)

(Prominent example: just now while writing this mail, i saw for the
first time how ${1+$@} works.  Ingenious approach, even if a bit
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?)

--=20
Piet Delport [EMAIL PROTECTED]
Today's subliminal thought is:

--a2FkP9tdjPU2nyhF
Content-Type: application/pgp-signature
Content-Disposition: inline

-BEGIN PGP SIGNATURE-
Version: GnuPG v1.0.6 (FreeBSD)

iD8DBQE7pB2mzRUP82sZFCcRAvCVAJ4jzkyFEmALLlEhocnWHQAvXxm4qgCffPxJ
tpv05IQHXabtYMM1jKfdM6c=
=3Ffj
-END PGP SIGNATURE-

--a2FkP9tdjPU2nyhF--