Re: $((expr)) allows the hexadecimal constant "0x"

2023-12-12 Thread Steffen Nurpmeso
Koichi Murase wrote in
 :
 |2023年12月10日(日) 15:58 Koichi Murase :
 |> 2023年12月10日(日) 14:13 Martin D Kealey :
 ...
 |> I'm not a big fan of `10#[-+]digits' and invalidating `10#' either
 ...
 |I checked the behaviors of different shells because I was interested
 |in them.  They seem to vary more than I expected.
 |
 || $((10#)) | $((2*10#-1)) | $((2*10#- 1))
 |--|--|--|---
 |bash-5.0  | 0| -1   | -1
 |bash-5.1  | error| error| error
 |ksh93u| 0| -2   | -1
 |ksh93v| error| error| error
 |mksh  | 0| -1   | -1
 |zsh   | 0| -2   | error
 |
 |ksh93u is tested with "Version AJM 93u+m/1.0.3 2022-08-25" and
 |"Version AJM 93u+ 2012-08-01". ksh93v is tested with "Version A
 |2020.0.0" (strictly speaking, this is not 93v but developed based on
 |93v).  $((2*10# -1)) was the same as $((2*10#-1)). $((2*10# - 1)) was
 |the same as $((2*10#- 1)).

It is totally off-topic, but please let me add the results for the
MUA i maintain (ie the next version that includes $(()), but the
cold is now over a year old):

  ? echo $((10#))
  .. Bad $(()) substitution: unknown operator: 10#: stop near: 10#

Derived from the ISO C standard, i thought when 0x is 0 rest x,
then that is 10 rest #, and that is not a valid arithmetic
expression.  $((10#8)) would echo "8" for my one, as below.

  ? echo $((2*10#-1))
  -2
  ? echo $((2*10#- 1))
  ..: Bad $(()) substitution: unknown operator: 2*10#- 1: stop near: 10#- 1

This is because field padding is not supported: "- 1" is not
a negative value, but a hyphen-minus, a space, and a positive
decimal.

  ? echo $((2*10#  -1))
  -2

As above, $(()) uses a convenience mode

  /*! Relaxed \a{base} 0 convenience: if the input used \c{BASE#number} number 
sign syntax,
   * then the scan will be restarted anew with the given base.
   * Like this an UI can be permissive and support \c{s='  -008'; eval 10#\$s} 
out of the box
   * (it would require a lot of logic otherwise). */
  su_IDEC_MODE_BASE0_NUMSIG_RESCAN = 1u<<3,

I thought this would be a good idea, and i like it in practice.
Here it is local to $(()) in addition.

--steffen
|
|Der Kragenbaer,The moon bear,
|der holt sich munter   he cheerfully and one by one
|einen nach dem anderen runter  wa.ks himself off
|(By Robert Gernhardt)
|
| Only in December: lightful Dubai COP28 Narendra Modi quote:
|  A small part of humanity has ruthlessly exploited nature.
|  But the entire humanity is bearing the cost of it,
|  especially the inhabitants of the Global South.
|  The selfishness of a few will lead the world into darkness,
|  not just for themselves but for the entire world.
|  [Christians might think of Revelation 11:18
|The nations were angry, and your wrath has come[.]
|[.]for destroying those who destroy the earth.
|   But i find the above more kind, and much friendlier]



Re: Add example of bind readline-command-line

2023-12-12 Thread Greg Wooledge
On Tue, Dec 12, 2023 at 10:06:49PM +0800, Dan Jacobson wrote:
> bash man page says
>   -v Display  readline variable names and values in such a way
>  that they can be re-read.
> Perhaps add an example of rereading via the bind command:

The man page also includes

   bind [-m keymap] [-lpsvPSVX]
   bind [-m keymap] [-q function] [-u function] [-r keyseq]
   bind [-m keymap] -f filename
   bind [-m keymap] -x keyseq:shell-command
   bind [-m keymap] keyseq:function-name
   bind [-m keymap] keyseq:readline-command

Given that the output of "bind -v" is several lines of text, I would try
the "bind -f filename" command first, to re-read such output.



[PATCH] preserve $_ value across prompt expansions

2023-12-12 Thread Grisha Levit
Since expanding a prompt string that contains a funsub will modify the
value of $_, would it make sense to restore the value of $_ after the
expansion is complete, as we do when executing PROMPT_COMMAND?

$ PS0='${ : X; }' bash --norc
bash-5.3$ : A
bash-5.3$ echo $_
X

P.S. Technically, it was also possible to modify the value of $_ during
prompt string expansion even before the addition of funsubs by doing a
direct assignment to `_' in an arithmetic expansion, something like:

PS1='${X[_=1]}$ '

but I hope that there is not a legitimate use case for preserving a $_
value so modified past the prompt string expansion phase, as this patch
will also cause such an assignment to be reverted.
---
 parse.y | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/parse.y b/parse.y
index e1e64f5c..57b13aa1 100644
--- a/parse.y
+++ b/parse.y
@@ -6126,7 +6126,7 @@ char *
 decode_prompt_string (char *string)
 {
   WORD_LIST *list;
-  char *result, *t, *orig_string;
+  char *result, *t, *orig_string, *last_lastarg;
   struct dstack save_dstack;
   int last_exit_value, last_comsub_pid, last_comsub_status;
 #if defined (PROMPT_STRING_DECODE)
@@ -6535,10 +6535,15 @@ not_escape:
   last_exit_value = last_command_exit_value;
   last_comsub_pid = last_command_subst_pid;
   last_comsub_status = last_command_subst_status;
+  last_lastarg = get_string_value ("_");
+  if (last_lastarg)
+last_lastarg = savestring (last_lastarg);
   list = expand_prompt_string (result, Q_DOUBLE_QUOTES, 0);
   free (result);
   result = string_list (list);
   dispose_words (list);
+  bind_lastarg (last_lastarg);
+  FREE (last_lastarg);
   last_command_exit_value = last_exit_value;
   last_command_subst_pid = last_comsub_pid;
   last_command_subst_status = last_comsub_status;
-- 
2.43.0



Add example of bind readline-command-line

2023-12-12 Thread Dan Jacobson
bash man page says
  -v Display  readline variable names and values in such a way
 that they can be re-read.
Perhaps add an example of rereading via the bind command:
$ bind 'set bell-style visible'
else the user might try:
$ echo set bell-style visible|bind
Yes, we see
bind readline-command-line
well maybe say
bind 'readline-command-line'



Re: Make reverse-i-search failure joltingly clear

2023-12-12 Thread Dan Jacobson
Well these days the chances of bells, visual or audible, getting
through are less and less, e.g.,
https://github.com/alacritty/alacritty/issues/1528
and on chromebook one must turn the bell on, etc.

So I still think something different should happen than each forlorn
character just mounting up on the screen.

Just like when the recycle department doesn't just let one pile stuff
up at their door when they are closed.