bug-bash
[Top][All Lists]
Advanced

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

bad case of parameter substitution with quotes (${p//x/y})


From: Yves
Subject: bad case of parameter substitution with quotes (${p//x/y})
Date: Wed, 23 Jun 2010 10:54:50 +0200
User-agent: Heirloom mailx 12.4pre 6/29/08

From: address@hidden
To: address@hidden

Configuration Information [Automatically generated, do not change]: FALSE!!!
Machine: i586
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='i586' 
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i586-mandriv    a-linux-gnu' 
-DCONF_VENDOR='mandriva' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' 
-DSHELL -DHAVE_CONFIG_H   -I.      -I.. -I../include -I../lib   -O2 -g -pipe 
-Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffe    
r-size=4 -fomit-frame-pointer -march=i586 -mtune=generic 
-fasynchronous-unwind-tables
uname output: Linux sp-ausy6.spna 2.6.27.37-desktop-1mnb #1 SMP Tue Oct 13 
13:33:31 EDT 2009 i686 Intel(R) Core(TM)2     CPU         T5500  @ 1.66GHz 
GNU/Linux
Machine Type: i586-mandriva-linux-gnu

Bash Version: 3.2
Patch Level: 19
Release Status: release

The above generated output is FALSE, as proven by:
address@hidden ~]$ ls -l /proc/$$/ | grep exe
lrwxrwxrwx  1 yves yves 0 2010-06-23 10:30 exe -> /opt/bash-4.1/bin/bash*
This is a self-compiled latest version (4.1) configured this way:
        ./configure --prefix=/opt/bash-4.1 --enable-alias \
        --enable-arith-for-command --enable-array-variables \
        --enable-bang-history --enable-brace-expansion \
        --enable-casemod-attributes --enable-casemod-expansions \
        --enable-command-timing --enable-cond-command \
        --enable-cond-regexp --enable-coprocesses \
        --enable-directory-stack --enable-dparen-arithmetic \
        --enable-extended-glob --enable-history --enable-job-control \
        --enable-multibyte --enable-net-redirections \
        --enable-process-substitution --enable-progcomp \
        --enable-prompt-string-decoding --enable-readline \
        --enable-select --with-installed-readline
        (installed readline was not used however, as it is too old)
and run this way while in the legacy bash-3.2 in gnome-terminal:
        exec /opt/bash-4.1/bin/bash

Description:
        I want to generate a "bash-proof" string by enclosing it in
        single quotes and managing enclosed single quotes. Basically, I
        would replace << word1   word'2 >> with << 'word1   word'"'"'2' >>.
        I can't find the syntax for doing this with the ${p//x/y}
        substitution (see example below).
        Actually, command #4 /does/ produce the right substitution, but
        as soon as I enclose it in double quotes, extra double-quotes
        appear, and I can't see the logic behind it, nor the logic
        behind my further tests' results.

Repeat-By:
        address@hidden 1]$ test="word1   word'2"
        address@hidden 2]$ echo "$test"
        word1   word'2
        address@hidden 3]$ echo ${test//'/'"'"'}
        > ^C
        address@hidden 4]$ echo ${test//"'"/"'\"'\"'"}
        word1 word'"'"'2
        address@hidden 5]$ echo "${test//"'"/"'\"'\"'"}"
        word1   word"'"'"'"2
        address@hidden 6]$ echo "${test//"'"/'\"'\"'}"
        > ^C
        address@hidden 7]$ echo "${test//"'"/\'\"\'\"\'}"
        word1   word\'"\'"\'2




reply via email to

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