You are not logged in.
Pages: 1
Say foo="Flabby Jiggleson\"s files". You want to replace the " with a '. Naturally, with a parameter expansion, you would
mv "$foo" "${foo/\"/'}"
Easy, right? Well, it fails, giving me a carat as if I was quoting a newline. So I try escaping it...
mv "$foo" "${foo/\"/\'}"
And I get...
Flabby Jiggleson\'s files
...with the backslash in it.
So ... now what?
Offline
This is a little ug-bug:
$ mv "$foo" "$(echo -e "${foo/\"/\047}")"
Offline
I asked in #bash; this is better
q1=\' q2=\";... "${foo/$q2/$q1}"
Offline
Hmm, interesting. Any way I could pass a literal ' ? $'\'' style?
Offline
No, the reason it acts that way has to do with POSIX compatability, I believe. The best way is indeed to use a variable.
q=\'; mv "$foo" "${foo/\"/$q}" # would be how I would do it.
Offline
Works for me... Am I missing something?
/home/fukawi2 $ FOO="I said \"Moo\" to you"
/home/fukawi2 $ echo $FOO
I said "Moo" to you
/home/fukawi2 $ echo ${FOO//\"/\'}
I said 'Moo' to you
EDIT: Interesting, if I quote it, then it breaks:
/home/fukawi2 $ echo "${FOO//\"/\'}"
I said \'Moo\' to you
Last edited by fukawi2 (2011-02-19 05:16:14)
Are you familiar with our Forum Rules, and How To Ask Questions The Smart Way?
BlueHackers // fscanary // resticctl
Offline
This is really weird behaviour, and almost seems like a bug if freak isn't right about it being a POSIX compatibility artifact. For the record, in zsh, "${foo/\"/'}" works, as I think it should in bash. "${foo/\"/\'}" gives an extra backslash in both shells, which also makes sense to me (since echo "\'" prints a backslash too).
Offline
Pages: 1