[Top][All Lists]

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

"${var/pattern/replace}", how to insert '}' in "replace"

From: Stephane Chazelas
Subject: "${var/pattern/replace}", how to insert '}' in "replace"
Date: Tue, 25 May 2004 08:51:02 +0100
User-agent: Mutt/1.5.6i

Configuration Information [Automatically generated, do not change]:
Machine: i686
OS: cygwin
Compiler: i686-pc-cygwin-gcc
Compilation CFLAGS:  -DPROGRAM='bash.exe' -DCONF_HOSTTYPE='i686' 
-DCONF_OSTYPE='cygwin' -DCONF_MACHTYPE='i686-pc-cygwin' -DCONF_VENDOR='pc' 
-I/home/RLandheer/cygwin-contrib/bash/2.05b-16/bash-2.05b/lib  -O2
uname output: CYGWIN_NT-5.0 frhdtmp102861 1.5.9(0.112/4/2) 2004-03-18 23:05 
i686 unknown unknown Cygwin
Machine Type: i686-pc-cygwin

Bash Version: 2.05b
Patch Level: 0
Release Status: release


Not really a bug, but a limitation in that parameter expansion.
It's impossible to have a '}' in the right hand side of a
substitution when the parameter is inside double quotes.

bash-2.05b$ a=a
bash-2.05b$ echo "${a/a/  \}}"
bash-2.05b$ echo "${a/a/'  }'}"
'  }'
bash-2.05b$ echo "${a/a/"  }"}"
"  }"

The only way is to use an additional variable:

bash-2.05b$ b=${a/a/  \}}
bash-2.05b$ echo $b


bash-2.05b$ brace='}'
bash-2.05b$ echo "${a/a/  $brace}"

Compare with zsh:

~$ echo "${a/a/  \}}"

This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 

reply via email to

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