bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: "printf %d ''" should diagnose the empty string


From: Greg Wooledge
Subject: Re: "printf %d ''" should diagnose the empty string
Date: Mon, 10 Feb 2025 09:42:40 -0500
User-agent: Mutt/1.10.1 (2018-07-13)

On Mon, Feb 10, 2025 at 15:20:55 +0100, Phi Debian wrote:
> If 'best *general*' refer to the shortest line noise does
> 
> $((${i/?([-+])/&10#}))
> 
> Qualify for better than best ? :-) if so you may add in your web bible
> don't forget to mention the inventor :-)

Can you please explain *how* this is working in older bash versions?
According to the CHANGES file, the processing of `&' by patsub_replacement
is new in bash 5.2.  And yet:

hobbit:~$ bash-2.05b
bash-2.05b: /home/greg/.bashrc: line 95: syntax error in conditional 
expression: unexpected token `('
bash-2.05b: /home/greg/.bashrc: line 95: syntax error near `+(['
bash-2.05b: /home/greg/.bashrc: line 95: `    if [[ $letters != +([A-Z]) ]]; 
then'
hobbit:~$ shopt | grep extglob
extglob         off
hobbit:~$ var=-023
hobbit:~$ echo "$(( ${var/?([-+])/&10#} ))"
-19

So, not only is the & being respected, but the extended glob is also
working, despite extglob being visibly disabled.  Not to mention, this
version is decades older than the patsub_replacement feature, at least
according to the documentation we have.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]