[Top][All Lists]

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

Re: Problem in var substitution with / and \

From: Greg Wooledge
Subject: Re: Problem in var substitution with / and \
Date: Mon, 14 Jan 2019 08:57:39 -0500
User-agent: NeoMutt/20170113 (1.7.2)

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?

reply via email to

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