No escape from the dollar sign in SED
| Newsgroups | gmane.editors.sed.user |
|---|---|
| Message-ID | <[email protected]> |
I was reading the excellent SED FAQ bud could not find an alternate solution to the following: The script below replaces the literal string $path with the contents of variable $usb The only way I could get this to work under busybox ash is with completely bare \\$ to escape the literal $path in two separate chunks as \\$'path' which is REALLY weird. root@zero:~# usb='/mnt/stick'; echo 'Path $path is it!' | sed -r 's|'\\$'path'"|$usb|g" Path /mnt/stick is it! It's great that it works because it allows me to pre-process my here-block before I write it out to a file, but jeepers it would be nice to understand what's happening and whether there are any other ways to do this under busybox with ash. Here is the slightly simplified here-doc version which I actually use: usb='/mnt/stick' cat <<-'EOF' | sed -r 's|'\\$"path|$usb|g" echo and here it is: ftpdir=$path echo more stuff EOF Best regards Stepan Novotny [Non-text portions of this message have been removed]