Problem in var substitution with / and \
Configuration Information [Automatically generated, do not change]: Machine: x86_64 OS: linux-gnu Compiler: gcc Compilation CFLAGS: -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-plt -DDEFAULT_PATH_VALUE='/usr/local/sbin:/usr/local/bin:/usr/bin' -DSTANDARD_UTILS_PATH='/usr/bin' -DSYS_BASHRC='/etc/ba> uname output: Linux euler 4.20.0-arch1-1-ARCH #1 SMP PREEMPT Mon Dec 24 03:00:40 UTC 2018 x86_64 GNU/Linux Machine Type: x86_64-pc-linux-gnu Bash Version: 5.0 Patch Level: 0 Release Status: release Description: If a variable contains one '/' (or many) and if this '/' is escaped with '\' by substitution mechanism and if the escaped variable is concatenated with a string containing '/' as prefix, and another string containing '/' as suffix then all characters in prefix and suffix are escaped with '\' The problem does not occurs in a "" context Repeat-By: URL=http://example.com ESCAPED_URL=${URL//\//\\\/} echo 'My URL: '$ESCAPED_URL' ... OK' echo '/My URL: http:\/\/example.com ... OK/' echo "/My URL: $ESCAPED_URL ... OK/" echo '/My URL: '$ESCAPED_URL' ... KO/'
Re: Problem in var substitution with / and \
On Mon, Jan 14, 2019 at 12:51:37PM +0100, Jean-François Berroyer wrote: > If a variable contains one '/' (or many) > and if this '/' is escaped with '\' by substitution mechanism > and if the escaped variable is concatenated with a string containing '/' as > prefix, and another string containing '/' as suffix > then all characters in prefix and suffix are escaped with '\' > The problem does not occurs in a "" context > > Repeat-By: > URL=http://example.com > ESCAPED_URL=${URL//\//\\\/} > echo 'My URL: '$ESCAPED_URL' ... OK' > echo '/My URL: http:\/\/example.com ... OK/' > echo "/My URL: $ESCAPED_URL ... OK/" > echo '/My URL: '$ESCAPED_URL' ... KO/' I cannot reproduce whatever problem you're seeing. wooledg:~$ bash-5.0 wooledg:~$ URL=http://example.com wooledg:~$ ESCAPED_URL=${URL//\//\\\/} wooledg:~$ echo 'My URL: '$ESCAPED_URL' ... OK' My URL: http:\/\/example.com ... OK wooledg:~$ echo "/My URL: $ESCAPED_URL ... OK/" /My URL: http:\/\/example.com ... OK/ Looks correct to me. What output are you getting?
Re: Problem in var substitution with / and \
On 1/14/19 6:51 AM, Jean-François Berroyer wrote: > Bash Version: 5.0 > Patch Level: 0 > Release Status: release > > Description: > If a variable contains one '/' (or many) > and if this '/' is escaped with '\' by substitution mechanism > and if the escaped variable is concatenated with a string containing '/' as > prefix, and another string containing '/' as suffix > then all characters in prefix and suffix are escaped with '\' > The problem does not occurs in a "" context > > Repeat-By: > URL=http://example.com > ESCAPED_URL=${URL//\//\\\/} > echo 'My URL: '$ESCAPED_URL' ... OK' > echo '/My URL: http:\/\/example.com ... OK/' > echo "/My URL: $ESCAPED_URL ... OK/" > echo '/My URL: '$ESCAPED_URL' ... KO/' See if this fixes it: http://lists.gnu.org/archive/html/bug-bash/2019-01/msg00087.html -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, UTech, CWRUc...@case.eduhttp://tiswww.cwru.edu/~chet/