[Bug Report] The Unexpected Behavior When Using ANSI Escape Code

2022-03-20 Thread Michaelll Lee
*Below are generated automatically by **'/usr/bin/bashbug' due to the
absence of 'rmail**’** command.*


---


*From:* Michael(lwl2...@gmail.com)
*To:* bug-bash@gnu.org
*Subject: *The Unexpected Behavior When Using ANSI Escape Code.

*Configuration Information [Automatically generated, do not change]:*
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -march=x86-64 -mtune=generic -O2 -pipe -fno-plt
-DDEFAULT_PATH_VALUE='/usr/local/sbin:/usr/local/bin:/usr/bin'
-DSTANDARD_UTILS_PATH='/usr/bin' -DSYS_BASHRC='/etc/bash.bashrc'
-DSYS_BASH_LOGOUT='/etc/bash.bash_logout' -DNON_INTERACTIVE_LOGIN_SHELLS
uname output: Linux arch80g 5.16.13-arch1-1 #1 SMP PREEMPT Tue, 08 Mar 2022
20:07:36 + x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu

Bash Version: 5.1
Patch Level: 16
Release Status: release

*Description:*

Background: A normal Bash user for a while.

When ``PS1’’ environment variable contains the ANSI escape codes, Bash will
behavior unexpectedly when Copy&Paste the content from clipboard using
Ctrl+V. This unexpected behaviour could be easily reproduced in a few steps.

Reproduceable steps are:

1) $ PS1='---Test \\ \e[0m ---\\$ '
 [Press  Key]
2) [Paste '123456789_123456789_' with ]

3) [Press  Key]

4) [Everything Is Fine]

5) [Paste '123456789_123456789_123456789_' with ]

6) [Press  Key]

7) ---Test \  ---$ 1234123456789_123456789_123456789
 [Result in Extra Charavters: The Leading '1234']

8) [Paste '123456789_123456789_']

9) [Press  Key]

10) [Everything Is Fine]

According to my limited tests, this behavior (i.e., Step7) could exist on
serveral platforms on which the BASH_VERSION is 5.x.x. However, this
behavior cannot be found on the same platforms while 4.x.x/3.x.x version of
Bash is invoked.

When the steps mentioned above being applied to other counterparts which
currently being as active development as Bash, Step7 would not happen for
them.

Hence, it is a reasonable guess that this might be bug for 5.x.x version of
Bash. If not, that would be my misuse of Bash, and would appreciate for
taking time reading my report.


*Repeat-By:*
No currently.

*Fix:*
Would be glad to provide a fix if I'm capable of.



---

2022/03/20
Michael Lee
lwl2...@gmail.com


Re: [Bug Report] The Unexpected Behavior When Using ANSI Escape Code

2022-03-20 Thread Andreas Schwab
On Mär 20 2022, Michaelll Lee wrote:

> 1) $ PS1='---Test \\ \e[0m ---\\$ '

Read the manual about non-printing characters in the prompt.

https://www.gnu.org/software/bash/manual/html_node/Controlling-the-Prompt.html

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."



for loop over parameter expansion of array can miss resulted empty list

2022-03-20 Thread Alexey via Bug reports for the GNU Bourne Again SHell

Hello.

Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -g -O2 -fstack-protector-strong -Wformat 
-Werror=format-security -Wall
uname output: Linux alex 5.16.0-3-amd64 #1 SMP PREEMPT Debian 5.16.11-1 
(2022-02-25) x86_64 GNU/Linux

Machine Type: x86_64-pc-linux-gnu

Bash Version: 5.1
Patch Level: 16
Release Status: release

Description:
  If use 'Parameter Expansion', for example 'Remove matching suffix 
pattern', on array and try to iterate over expansion result with for 
loop, may occur that loop body will not be executed at all.


Repeat-By:
  Code: x=("/"); for i in "${x[@]%/}"; do echo "i is '$i'"; done
  Result: none
  Expected result: i is ''

Expected behavior:
  like for an array with empty element
  Code: x=(""); for i in "${x[@]}"; do echo "i is '$i'"; done
  Result: i is ''

  another example, show that problems occurs only with empty resulted 
list

  Code: x=("/" "//"); for i in "${x[@]%/}"; do echo "i is '$i'"; done
  Result: i is ''
  i is '/'


Regards,
Alexey