Re: Zero-length indexed arrays

2021-12-21 Thread Lawrence Velázquez
On Tue, Dec 21, 2021, at 10:48 PM, Dale R. Worley wrote:
> Lawrence Velázquez  writes:
>> Did you mean to say that ${#FOO[*]} causes an error?  Because
>> ${FOO[*]} does not, a la $*:
>
> The case that matters for me is the Bash that ships with "Oracle Linux".
> Which turns out to be version 4.2.46(2) from 2011, which is a lot older
> than I would expect.  But it *does* cause an error in that verison:
>
> $ ( set -u ; FOO=() ; echo "${FOO[@]}" )
> bash: FOO[@]: unbound variable
> $ bash -uc ': "${FOO[*]}"'
> bash: FOO[*]: unbound variable
> $ 
>
>> Like ${FOO[*]}, ${FOO[@]} and $@ are exempt from ''set -u''.
>
> It looks like that's a change since 4.2.46.

Yes, it appears to be from 4.4.

https://git.savannah.gnu.org/cgit/bash.git/tree/CHANGES?id=15409324f1974d41c183904ad575da7188058c1c#n1512

This document details the changes between this version,
bash-4.4-rc2, and the previous version, bash-4.4-beta2.

[...]

3.  New Features in Bash

a.  Using ${a[@]} or ${a[*]} with an array without any assigned
elements when the nounset option is enabled no longer throws
an unbound variable error.


> Is there text in the manual page about that?

I don't know.

-- 
vq



Re: Zero-length indexed arrays

2021-12-21 Thread Greg Wooledge
On Tue, Dec 21, 2021 at 10:48:07PM -0500, Dale R. Worley wrote:
> Lawrence Velázquez  writes:
> > Did you mean to say that ${#FOO[*]} causes an error?  Because
> > ${FOO[*]} does not, a la $*:
> 
> The case that matters for me is the Bash that ships with "Oracle Linux".
> Which turns out to be version 4.2.46(2) from 2011, which is a lot older
> than I would expect.  But it *does* cause an error in that verison:
> 
> $ ( set -u ; FOO=() ; echo "${FOO[@]}" )
> bash: FOO[@]: unbound variable

unicorn:~$ bash-4.1 -c 'set -u; a=(); echo "${foo[@]}"'
bash-4.1: foo[@]: unbound variable
unicorn:~$ bash-4.2 -c 'set -u; a=(); echo "${foo[@]}"'
bash-4.2: foo[@]: unbound variable
unicorn:~$ bash-4.3 -c 'set -u; a=(); echo "${foo[@]}"'
bash-4.3: foo[@]: unbound variable
unicorn:~$ bash-4.4 -c 'set -u; a=(); echo "${foo[@]}"'

unicorn:~$ 

I would recommend not using set -u.  It's not as bad as set -e, but it's
still pretty bad.  It breaks what would otherwise be valid scripts, and
the breakage is not always easy to predict, as you've now seen.  Especially
when you need to support multiple bash versions, or even multiple shells.



Re: Zero-length indexed arrays

2021-12-21 Thread Dale R. Worley
Lawrence Velázquez  writes:
> Did you mean to say that ${#FOO[*]} causes an error?  Because
> ${FOO[*]} does not, a la $*:

The case that matters for me is the Bash that ships with "Oracle Linux".
Which turns out to be version 4.2.46(2) from 2011, which is a lot older
than I would expect.  But it *does* cause an error in that verison:

$ ( set -u ; FOO=() ; echo "${FOO[@]}" )
bash: FOO[@]: unbound variable
$ bash -uc ': "${FOO[*]}"'
bash: FOO[*]: unbound variable
$ 

> Like ${FOO[*]}, ${FOO[@]} and $@ are exempt from ''set -u''.

It looks like that's a change since 4.2.46.  Is there text in the manual
page about that?

Dale



Re: Format specifier for printf in manual

2021-12-21 Thread Chet Ramey

On 12/21/21 6:48 PM, fatipa...@tutanota.com wrote:


If you want to read about the format specifiers, the first link from
Lawrence's message is authoritative.

Is printf an external program to bash? In this age, one uses a simple 
search on a manual rather

than reading the 200 pages.


It's a builtin that behaves the same as, with additions, as the standalone
version. There's no need to duplicate that information; the differences are
what's important to put in the man page.


--
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRUc...@case.eduhttp://tiswww.cwru.edu/~chet/



Format specifier for printf in manual

2021-12-21 Thread fatiparty--- via Bug reports for the GNU Bourne Again SHell



-- 
 Sent with Tutanota, the secure & ad-free mailbox. 



Dec 21, 2021, 23:35 by chet.ra...@case.edu:

> On 12/21/21 6:12 PM, fatiparty--- via Bug reports for the GNU Bourne Again 
> SHell wrote:
>
>> It is still something that needs fixing.  Cannot see that it is described in 
>> the bash manual.  No mention of %s %d %o and related things.  Certainly not 
>> in the link you included.
>>
>
> It's not a bug. There is no need to duplicate information from printf(1)
> and printf(3) in the bash man page. That's how you push the man `page'
> over 200 pages.
>
> If you want to read about the format specifiers, the first link from
> Lawrence's message is authoritative.
>
Is printf an external program to bash? In this age, one uses a simple search on 
a manual rather
than reading the 200 pages.  


> On my system, `man -s 1 printf' and `man -s 3 printf' produce the information 
> you want.
>



Re: Format specifier for printf in manual

2021-12-21 Thread Chet Ramey
On 12/21/21 6:12 PM, fatiparty--- via Bug reports for the GNU Bourne Again 
SHell wrote:



It is still something that needs fixing.  Cannot see that it is described in 
the bash manual.  No mention of %s %d %o and related things.  Certainly not in 
the link you included.


It's not a bug. There is no need to duplicate information from printf(1)
and printf(3) in the bash man page. That's how you push the man `page'
over 200 pages.

If you want to read about the format specifiers, the first link from
Lawrence's message is authoritative.

On my system, `man -s 1 printf' and `man -s 3 printf' produce the 
information you want.



--
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRUc...@case.eduhttp://tiswww.cwru.edu/~chet/



Format specifier for printf in manual

2021-12-21 Thread fatiparty--- via Bug reports for the GNU Bourne Again SHell
Dec 21, 2021, 22:51 by v...@larryv.me:

> On Tue, Dec 21, 2021, at 5:40 PM, fatiparty--- via Bug reports for the GNU 
> Bourne Again SHell wrote:
>
>> Have tried to read some information about the format specifier for 
>> printf, particularly the width, precision and left justification for 
>> %s, but could not find any.
>>
>
> https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap05.html#tag_05
> https://pubs.opengroup.org/onlinepubs/9699919799/utilities/printf.html#tag_20_94_13
> https://www.gnu.org/software/bash/manual/html_node/Bash-Builtins.html#index-printf
>
> Please do not use this mailing list for inquiries that are not about
> bugs.  There is no bug here.
>
> -- 
> vq
>
It is still something that needs fixing.  Cannot see that it is described in 
the bash manual.  No mention of %s %d %o and related things.  Certainly not in 
the link you included.



Re: Format specifier for printf in manual

2021-12-21 Thread Lawrence Velázquez
On Tue, Dec 21, 2021, at 5:40 PM, fatiparty--- via Bug reports for the GNU 
Bourne Again SHell wrote:
> Have tried to read some information about the format specifier for 
> printf, particularly the width, precision and left justification for 
> %s, but could not find any.

https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap05.html#tag_05
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/printf.html#tag_20_94_13
https://www.gnu.org/software/bash/manual/html_node/Bash-Builtins.html#index-printf

Please do not use this mailing list for inquiries that are not about
bugs.  There is no bug here.

-- 
vq



Format specifier for printf in manual

2021-12-21 Thread fatiparty--- via Bug reports for the GNU Bourne Again SHell


Have tried to read some information about the format specifier for printf, 
particularly the width, precision and left justification for %s, but could not 
find any.