bug-bash
[Top][All Lists]
Advanced

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

Re: pattern substitution expands "~" even in quoted variables


From: Eduardo A . Bustamante López
Subject: Re: pattern substitution expands "~" even in quoted variables
Date: Fri, 7 Mar 2014 16:15:05 -0800
User-agent: Mutt/1.5.21 (2010-09-15)

On Fri, Mar 07, 2014 at 05:21:53PM +0100, Lars Wendler wrote:
> Configuration Information 
> [Automatically generated, do not change]:
> Machine: x86_64
> OS: linux-gnu
> Compiler: x86_64-pc-linux-gnu-gcc
> Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64' 
> -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-pc-linux-gnu' 
> -DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL 
> -DHAVE_CONFIG_H   -I. -I./include -I. -I./include -I./lib  
> -DDEFAULT_PATH_VALUE='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
>  -DSTANDARD_UTILS_PATH='/bin:/usr/bin:/sbin:/usr/sbin' 
> -DSYS_BASHRC='/etc/bash/bashrc' -DSYS_BASH_LOGOUT='/etc/bash/bash_logout' 
> -DNON_INTERACTIVE_LOGIN_SHELLS -DSSH_SOURCE_BASHRC -march=barcelona 
> -mtune=barcelona -O2 -pipe
> uname output: Linux shanghai 3.12.13 #2 SMP PREEMPT Wed Mar 5 17:26:09 CET 
> 2014 x86_64 Quad-Core AMD Opteron(tm) Processor 2389 AuthenticAMD GNU/Linux
> Machine Type: x86_64-pc-linux-gnu
> 
> Bash Version: 4.3
> Patch Level: 0
> Release Status: release
> 
> Description:
> 
> bash-4.3 seems to expand a "~" (tilde character) with full homepath in a 
> pattern substitution even when the variable is embraced by double quotes.
> 
> Repeat-By:
> 
> replace_with_tilde() { P="foo_bar" ; echo ${P/_/~} ;  echo "${P/_/~}" ; }
> 
> 
> bash-4.2.45:
> 
> ~% replace_with_tilde
> foo/home/polynomial-cbar
> foo~bar
> 
> 
> bash-4.3.0:
> 
> ~% replace_with_tilde
> foo/home/polynomial-cbar
> foo/home/polynomial-cbar

(1) You're not quoting it right:

address@hidden:~$ for shell in /bin/bash ~/local/bin/bash; do "$shell" -c 
'p=foo_bar; echo "${p/_/\~} $BASH_VERSION"'; done
foo\~bar 4.2.37(1)-release
foo~bar 4.3.0(2)-release

(2) In fact, this change in 4.3 is a fix to an old (and a bit weird)
behavior, see:

- http://lists.gnu.org/archive/html/bug-bash/2012-02/msg00106.html
- http://lists.gnu.org/archive/html/bug-bash/2013-03/msg00099.html

If you want the old behavior:

address@hidden:~$ ~/local/bin/bash -c 'shopt -s compat42; p=foo_bar; echo 
"${p/_/\~} $BASH_VERSION"'
foo\~bar 4.3.0(2)-release

-- 
Eduardo Alan Bustamante López



reply via email to

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