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