Re: Typo in Bash Reference Manual

2025-06-29 Thread Robert Elz
Date:Sun, 29 Jun 2025 08:13:07 -0600
From:Stan Marsh 
Message-ID:  

  | So, is this POSIX, or just a dash-extension?

It is original Bourne Shell (from 7th edition Bell Labs Unix)
and is (or should be) supported by every Bourne-compatible shell.

It definitely is in POSIX.

kre



Re: Typo in Bash Reference Manual

2025-06-29 Thread Stan Marsh


>"Note that a negative offset must be separated from the [non-following]
>colon by at least one space to avoid being confused with the ':-'
>expansion,' since a negative offset can exist immediately beside a
>subsequent colon.

>Wiley

Note, incidentally, that it is not strictly true that a negative offset has
to be preceded by a space.  A zero will work as well.  And I think that is
clearer.  I.e., instead of:

# Print the last 2 characters of $HOME
$ echo ${HOME: -2}

You can do:

$ echo ${HOME:0-2}

Or even:

$ echo ${HOME:7-9}

=
Please do not send me replies to my posts on the list.
I always read the replies via the web archive, so CC'ing to me is unnecessary.

Note that they always end up in my Spam file anyway, so it is annoying to have 
to
periodically clean that out.



Re: Typo in Bash Reference Manual

2025-06-29 Thread Stan Marsh
And here is another interesting thing inspired by this thread.

I always thought the "colon-free" versions of the P.E. was a bash-ism, but
experimentation shows that it works in "dash" as well.  And "man dash" contains
the following text:

   In the parameter expansions shown previously, use of the colon in the format 
re-
 sults in a test for a parameter that is unset or null; omission of the 
colon re-
 sults in a test for a parameter that is only unset.

So, is this POSIX, or just a dash-extension?

=
Please do not send me replies to my posts on the list.
I always read the replies via the web archive, so CC'ing to me is unnecessary.

Note that they always end up in my Spam file anyway, so it is annoying to have 
to
periodically clean that out.



Re: Typo in Bash Reference Manual

2025-06-29 Thread Greg Wooledge
On Sun, Jun 29, 2025 at 21:51:52 +0700, Robert Elz wrote:
> Date:Sun, 29 Jun 2025 08:13:07 -0600
> From:Stan Marsh 
> Message-ID:  
> 
>   | So, is this POSIX, or just a dash-extension?
> 
> It is original Bourne Shell (from 7th edition Bell Labs Unix)
> and is (or should be) supported by every Bourne-compatible shell.
> 
> It definitely is in POSIX.

In fact, the colon-less forms ${var-word} and so on were the originals.
The colon variants ${var:-word} were added later, IIRC by ksh.

See  for a Bourne shell
man page, showing ${parameter+word} and so on.



Re: Typo in Bash Reference Manual

2025-06-29 Thread Greg Wooledge
On Sun, Jun 29, 2025 at 06:39:18 -0600, Stan Marsh wrote:
> Note, incidentally, that it is not strictly true that a negative offset has
> to be preceded by a space.  A zero will work as well.  And I think that is
> clearer.  I.e., instead of:
> 
> # Print the last 2 characters of $HOME
> $ echo ${HOME: -2}
> 
> You can do:
> 
> $ echo ${HOME:0-2}

Or ${HOME:(-2)} if you like.



Re: Typo in Bash Reference Manual

2025-06-29 Thread Lawrence Velázquez
On Sun, Jun 29, 2025, at 11:41 AM, Greg Wooledge wrote:
> The colon variants ${var:-word} were added later, IIRC by ksh.

Looks like the System III shell released them first:

https://www.in-ulm.de/~mascheck/bourne/#system3

-- 
vq