read -a ignores upper- and lowercase flags

2016-04-08 Thread Geir Hauge
Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: darwin14.5.0
Compiler: /usr/bin/clang
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64' 
-DCONF_OSTYPE='darwin14.5.0' -DCONF_MACHTYPE='x86_64-apple-darwin14.5.0' 
-DCONF_VENDOR='apple' -DLOCALEDIR='/opt/local/share/locale' -DPACKAGE='bash' 
-DSHELL -DHAVE_CONFIG_H -DMACOSX   -I.  -I. -I./include -I./lib  
-I/opt/local/include -pipe -Os -DSSH_SOURCE_BASHRC -arch x86_64
uname output: Darwin MacGeir 14.5.0 Darwin Kernel Version 14.5.0: Tue Sep  1 
21:23:09 PDT 2015; root:xnu-2782.50.1~1/RELEASE_X86_64 x86_64
Machine Type: x86_64-apple-darwin14.5.0

Bash Version: 4.3
Patch Level: 42
Release Status: release

Description:

read -ra var  doesn't change the casing of the strings it assigns
when var has been declared with -l or -u.

read without -a, and mapfile both work as expected.

I also tested the latest devel branch to confirm the bug is still
present there.

Repeat-By:

declare -l a b c d
a=( HEllO woRLd )
read -r b <<< "HEllO woRLd"
read -ra c <<< "HEllO woRLd"
mapfile d <<< "HEllO woRLd"
declare -p a b c d

Output:

declare -al a=([0]="hello" [1]="world")
declare -l b="hello world"
declare -al c=([0]="HEllO" [1]="woRLd")
declare -al d=([0]=$'hello world\n')

-- 
Geir Hauge



Re: read -a ignores upper- and lowercase flags

2016-04-08 Thread Chet Ramey
On 4/8/16 6:03 AM, Geir Hauge wrote:

> Bash Version: 4.3
> Patch Level: 42
> Release Status: release
> 
> Description:
> 
> read -ra var  doesn't change the casing of the strings it assigns
> when var has been declared with -l or -u.

Thanks for the report.  This will be fixed in bash-4.4.

Chet

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



Bash 4.4-rc1 incompatibility with future Emacs $EMACS

2016-04-08 Thread Paul Eggert
[Sending this to bug-bash@gnu.org since the mail was rejected by 
bash-test...@cwru.edu.]


Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64'
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-unknown-linux-gnu'
-DCONF_VENDOR='unknown' -DLOCALEDIR='/tmp/prefix/share/locale'
-DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H -DDEBUG -DMALLOC_DEBUG -I. -I.
-I./include -I./lib   -g -O2 -Wno-parentheses -Wno-format-security
uname output: Linux penguin.cs.ucla.edu 4.4.6-300.fc23.x86_64 #1 SMP Wed
Mar 16 22:10:37 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
Machine Type: x86_64-unknown-linux-gnu

Bash Version: 4.4
Patch Level: 0
Release Status: rc1

Description:
 Please see attached patch.

Repeat-By:
 Please see attached patch.

Fix:
 Please see attached patch.
From 75d409f43d09d1323416db90121bc6bf54cbc3ff Mon Sep 17 00:00:00 2001
From: Paul Eggert 
Date: Fri, 8 Apr 2016 11:22:39 -0700
Subject: [PATCH] Fix compatibility problem with INSIDE_EMACS etc.

The checks for deciding whether bash is being run in a GNU Emacs shell
window have been tweaked to better support how the future versions of
Emacs will set environment variables.

Here are details about the problem.  Bash's heuristic that infers
whether Bash is being run inside the Emacs 'M-x term' command will
have problems when running inside future versions of Emacs.  Although
Emacs 25 'M-x term' will continue to set both variables (e.g.,
EMACS='25.1 (term:0.96)' and INSIDE_EMACS='25.1,term:0.96') for
compatibility with Bash 4.3 and earlier, we would like Bash 4.4 and
later to work with future versions of Emacs that that set only
INSIDE_EMACS.

Problem reported by Phillip Lord in .

* shell.c (main): Tweak tests for whether we are running in an Emacs
shell window, to accommodate future Emacs versions better, and to
document and reflect historical practice more accurately.
---
 shell.c | 38 ++
 1 file changed, 30 insertions(+), 8 deletions(-)

diff --git a/shell.c b/shell.c
index 63f139b..c91baf0 100644
--- a/shell.c
+++ b/shell.c
@@ -570,25 +570,47 @@ main (argc, argv, env)
   set_default_locale_vars ();
 
   /*
-   * M-x term -> TERM=eterm EMACS=22.1 (term:0.96)	(eterm)
-   * M-x shell -> TERM=dumb EMACS=t			(no line editing)
-   * M-x terminal -> TERM=emacs-em7955 EMACS=		(line editing)
+   * M-x term -> TERM='eterm-color' INSIDE_EMACS='25.1,term:0.96' (eterm)
+   * M-x shell -> TERM='dumb' INSIDE_EMACS='25.1,comint' (no line editing)
+   *
+   * Older versions of Emacs may set EMACS to 't' or to something like
+   * '22.1 (term:0.96)' instead of (or in addition to) setting INSIDE_EMACS.
+   * They may set TERM to 'eterm' instead of 'eterm-color'.  They may have
+   * a now-obsolete command that sets neither EMACS nor INSIDE_EMACS:
+   * M-x terminal -> TERM='emacs-em7955' (line editing)
*/
   if (interactive_shell)
 {
-  char *term, *emacs;
+  char *term, *emacs, *inside_emacs;
+  int emacs_term, in_emacs;
 
   term = get_string_value ("TERM");
   emacs = get_string_value ("EMACS");
+  inside_emacs = get_string_value ("INSIDE_EMACS");
+
+  if (inside_emacs)
+	{
+	  emacs_term = strstr (inside_emacs, ",term:") != 0;
+	  in_emacs = 1;
+	}
+  else if (emacs)
+	{
+	  /* Infer whether we are in an older Emacs.  Do not accept
+	 just any value for EMACS, as the value might be an
+	 executable file name or a shell command.  */
+	  emacs_term = strstr (emacs, " (term:") != 0;
+	  in_emacs = emacs_term || STREQ (emacs, "t");
+	}
+  else
+	emacs_term = in_emacs = 0;
 
   /* Not sure any emacs terminal emulator sets TERM=emacs any more */
   no_line_editing |= STREQ (term, "emacs");
-  no_line_editing |= emacs && emacs[0] == 't' && emacs[1] == '\0' && STREQ (term, "dumb");
-  no_line_editing |= get_string_value ("INSIDE_EMACS") != 0;
+  no_line_editing |= in_emacs && STREQ (term, "dumb");
 
   /* running_under_emacs == 2 for `eterm' */
-  running_under_emacs = (emacs != 0) || STREQN (term, "emacs", 5);
-  running_under_emacs += STREQN (term, "eterm", 5) && emacs && strstr (emacs, "term");
+  running_under_emacs = in_emacs || STREQN (term, "emacs", 5);
+  running_under_emacs += emacs_term && STREQN (term, "eterm", 5);
 
   if (running_under_emacs)
 	gnu_error_format = 1;
-- 
2.5.5