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

2024-11-19 Thread #!microsuxx
the printf %d gets to be no print_out at all
u specify a % but no arg
means it wont try printf at all smth

printf %d '' we can talk about
returns 0
and looks normal so to me

On Tue, Nov 19, 2024, 8:46 PM Paul Eggert  wrote:

> Configuration Information [Automatically generated, do not change]:
> Machine: x86_64
> OS: linux-gnu
> Compiler: gcc -std=gnu23
> Compilation CFLAGS: -g -O2
> uname output: Linux penguin.cs.ucla.edu 6.11.6-200.fc40.x86_64 #1 SMP
> PREEMPT_DYNAMIC Fri Nov  1 16:09:34 UTC 2024 x86_64 GNU/Linux
> Machine Type: x86_64-pc-linux-gnu
>
> Bash Version: 5.3
> Patch Level: 0
> Release Status: beta
>
> Description:
>
> printf doesn't diagnose attempts to print empty strings as numbers. This
> doesn't conform to POSIX and disagrees with the traditional Unix printf
> command.
>
> Repeat-By:
>
> printf %d ''
>
> This should behave like "printf %d ' '", and should output a diagnostic
> and exit with status 1; instead it silently exits with status 0.
>
> Fix:
> Attached.


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

2024-11-19 Thread #!microsuxx
On Tue, Nov 19, 2024, 10:04 PM #!microsuxx  wrote:

> the printf %d gets to be no print_out at all
> u specify a % but no arg
> means it wont try printf at all smth
>
> printf %d '' we can talk about
> returns 0
> and looks normal so to me
>

sorry i missed u already did right
sorry ..

u can try posix mode if u care
i .. like it not erroring

On Tue, Nov 19, 2024, 8:46 PM Paul Eggert  wrote:
>
>> Configuration Information [Automatically generated, do not change]:
>> Machine: x86_64
>> OS: linux-gnu
>> Compiler: gcc -std=gnu23
>> Compilation CFLAGS: -g -O2
>> uname output: Linux penguin.cs.ucla.edu 6.11.6-200.fc40.x86_64 #1 SMP
>> PREEMPT_DYNAMIC Fri Nov  1 16:09:34 UTC 2024 x86_64 GNU/Linux
>> Machine Type: x86_64-pc-linux-gnu
>>
>> Bash Version: 5.3
>> Patch Level: 0
>> Release Status: beta
>>
>> Description:
>>
>> printf doesn't diagnose attempts to print empty strings as numbers. This
>> doesn't conform to POSIX and disagrees with the traditional Unix printf
>> command.
>>
>> Repeat-By:
>>
>> printf %d ''
>>
>> This should behave like "printf %d ' '", and should output a diagnostic
>> and exit with status 1; instead it silently exits with status 0.
>>
>> Fix:
>> Attached.
>
>


Re: [PATCH] lib/readline/doc makefiles clean targets

2024-11-19 Thread Chet Ramey

On 11/18/24 10:28 PM, Grisha Levit wrote:


This is one of the differences between the distributions and the devel
branch. y.tab.h is always in $(srcdir) in distributions, and the Makefiles
accommodate them in favor of the devel branch.


Could we install INSTALLED_HEADERS the same way as CREATED_HEADERS are?


I added a variant of this idea to accommodate installing from the devel
branch.

--
``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/



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

2024-11-19 Thread Paul Eggert

On 2024-11-19 13:05, #!microsuxx wrote:

u can try posix mode if u care


Certainly if Bash is in POSIX mode it should reject "printf %d ''", for 
the same reason it rejects "printf %d ' '" and "printf %d x" - POSIX 
requires it to diagnose any argument that isn't a C integer context.


However, I don't see why Bash should differ from POSIX behavior. Bash 
already diagnoses "printf %d x" and "printf %d ' '"; why should it be 
silent about "printf %d ''"?




Re: The 'source x' command doesn't keep variables set by x when source output is piped into other command

2024-11-19 Thread Chet Ramey

On 11/18/24 12:55 AM, Martin D Kealey wrote:



On Sun, 17 Nov 2024, 03:32 Chet Ramey, > wrote:


On 11/16/24 3:36 AM, Martin D Kealey wrote:
I don't think a disclaimer saying "this manual is not what it does not
claim to be" is particularly useful.


That's valid, but how else do we get people to read the correct document 
for their skill level, when their self-assessment will invariably be wrong? 
How can we reasonably expect users to assess their own skill level and 
choose a 'tutorial' when their instincts are telling them "yep I understand 
almost all of this stuff"?


Maybe I have a higher opinion of users than this? This is pretty scathing.

The Shell language /looks/ simple, while actually being one of the most 
complex languages in common use, and its multitude of subtle fishhooks 
effectively turns half the populace into Dunning-Kruger sufferers. 
Moreover, we are complicit in this: every new feature added to Bash makes 
it more useful, more attractive to new users.


OK, you have a problem with the language and its definition. Let's not
project that on everyone.


The morally right thing to do would be to shoo them away, not attract them.
In the meantime we owe them a duty of care.


Wow, you really don't think much of new users.

I've used Bash for about 30 years, and even I have to wonder whether the 
Shell manual should start with this warning instead:


"/If you're writing a new script from scratch, *STOP NOW*, and go and 
choose a different language - ANY language. No matter what you choose, it 
will be a better choice than the Shell language.


Maybe spend some time away from this. I don't think adding that helps
anyone -- me, users of any experience level, people who want to help --
anyone. It's just alienating.

Chet
--
``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/



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

2024-11-19 Thread Paul Eggert

Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc -std=gnu23
Compilation CFLAGS: -g -O2
uname output: Linux penguin.cs.ucla.edu 6.11.6-200.fc40.x86_64 #1 SMP 
PREEMPT_DYNAMIC Fri Nov  1 16:09:34 UTC 2024 x86_64 GNU/Linux

Machine Type: x86_64-pc-linux-gnu

Bash Version: 5.3
Patch Level: 0
Release Status: beta

Description:

printf doesn't diagnose attempts to print empty strings as numbers. This 
doesn't conform to POSIX and disagrees with the traditional Unix printf 
command.


Repeat-By:

printf %d ''

This should behave like "printf %d ' '", and should output a diagnostic 
and exit with status 1; instead it silently exits with status 0.


Fix:
Attached.From f2583bf297268c08b474c68b0a8a2188f8d555cf Mon Sep 17 00:00:00 2001
From: Paul Eggert 
Date: Tue, 19 Nov 2024 11:35:21 -0800
Subject: [PATCH] diagnose attempts to printf '' as a number

---
 builtins/printf.def | 4 ++--
 tests/printf.right  | 8 
 tests/printf.tests  | 5 +
 3 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/builtins/printf.def b/builtins/printf.def
index d7fc8f87..afe5cf7d 100644
--- a/builtins/printf.def
+++ b/builtins/printf.def
@@ -1374,7 +1374,7 @@ getint (int overflow_retval)
   ret = strtoimax (garglist->word->word, &ep, 0);
   overflow = (errno == ERANGE) || (ret < INT_MIN || ret > INT_MAX);
 
-  if (*ep)
+  if (*ep || ep == garglist->word->word)
 {
   sh_invalidnum (garglist->word->word);
   conversion_error = 1;
@@ -1401,7 +1401,7 @@ getintmax (void)
   errno = 0;
   ret = strtoimax (garglist->word->word, &ep, 0);
 
-  if (*ep)
+  if (*ep || ep == garglist->word->word)
 {
   sh_invalidnum (garglist->word->word);
   /* POSIX.2 says ``...a diagnostic message shall be written to standard
diff --git a/tests/printf.right b/tests/printf.right
index 7c2e19a5..1e274c5d 100644
--- a/tests/printf.right
+++ b/tests/printf.right
@@ -169,6 +169,14 @@ xx
 9223372036854775807
 ./printf.tests: line 365: printf: -9223372036854775815: Result too large
 -9223372036854775808
+./printf.tests: line 367: printf: : invalid number
+0
+./printf.tests: line 368: printf:  : invalid number
+0
+./printf.tests: line 369: printf: : invalid number
+30
+./printf.tests: line 370: printf: : invalid number
+30
 	one
 one\ctwo
 4\.2
diff --git a/tests/printf.tests b/tests/printf.tests
index af03960a..27ffcef2 100644
--- a/tests/printf.tests
+++ b/tests/printf.tests
@@ -364,6 +364,11 @@ TOOSMALL=-9223372036854775815
 printf '%d\n' "$TOOBIG"
 printf '%d\n' "$TOOSMALL"
 
+printf '%d\n' ''
+printf '%d\n' ' '
+printf '%*.*d\n' 10 '' 30
+printf '%*.*d\n' '' 10 30
+
 # tests variable assignment with -v
 ${THIS_SH} ./printf1.sub
 ${THIS_SH} ./printf2.sub
-- 
2.47.0



Re: AW: Built-in `test -a` returns incorrectly

2024-11-19 Thread Chet Ramey

On 11/19/24 2:31 AM, Klüver, Tibor wrote:

Hi,

thank you both for the detailed explanation. I had fully forgotten about the binary meaning of -a. However, it makes me wonder why this isn't more visibly documented. 


The current devel branch man page says this:


  The historical operator-precedence parsing with 4 or more  argu-
  ments  can  lead  to ambiguities when it encounters strings that
  look like primaries.  The POSIX standard has deprecated  the  -a
  and  -o  primaries and enclosing expressions within parentheses.
  Scripts should no longer use them.  It's much more  reliable  to
  restrict  test  invocations  to a single primary, and to replace
  uses of -a and -o with the shell's && and || list operators.


--
``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/