Re: No escape from the dollar sign in SED

"Sven Guckes [email protected] [sed-users]" <[email protected]> Wed, 4 Apr 2018 08:51:36 +0200
Newsgroups gmane.editors.sed.user
Message-ID <[email protected]>
* Stepan Novotny <[email protected]> [2018-04-04 07:07]:
> 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!

i used colons as a separator..

guckes@kudu:~> busybox ash
BusyBox v1.22.1 (Debian 1:1.22.0-9+deb8u1) built-in shell (ash)
Enter 'help' for a list of built-in commands.
~ $ usb='/mnt/stick'
~ $ echo 'Path $path is it!' | sed -r s:$path:$usb:g
sed: no previous regexp
~ $ echo 'Path $path is it!' | sed -r s:\$path:$usb:g
Path $path is it!
~ $ echo 'Path $path is it!' | sed -r s:\\$path:$usb:g
sed: unmatched ':'
~ $ echo 'Path $path is it!' | sed -r s:'\$'path:$usb:g
Path /mnt/stick is it!
~ $ echo 'Path $path is it!' | sed -r s:\\\$path:$usb:g
Path /mnt/stick is it!

i expected "\$path" to suffice.. but it didnt.
likewise with "\\$path".  but "'\$'" worked.
and then also "\\\$" did, too. o_O

i suppose it must be something with the minimalism of the
tools within busybox.. and maybe an older version of sed.
does anybody know about the "life of sed" within busybox?

i just downloaded busybox-1.28.3 (as of yesterday 2018-04-03):
 wget http://busybox.net/downloads/busybox-1.28.3.tar.bz2
 make menuconfig  # i did change some options, but.. who cares?
 make
 make CONFIG_PREFIX=/home/user/guckes install
 cd ~/bin; mv busybox busybox-1.28.3; ln -s !$ busybox

but.. no change. same results.

just for the record.. the "make menuconfig"
contains amenu for "Editors" with "sed (12 kb)".
that's only *twelve* kilobytes for sed! :-O
well, minised-1.15 had some 25.5KB. "big!" ;-)

but maybe you folks will find the solution.
here are the commands for testing again:

usb='/mnt/stick'
echo 'Path $path is it!' | sed -r s:$path:$usb:g
echo 'Path $path is it!' | sed -r s:\$path:$usb:g
echo 'Path $path is it!' | sed -r s:\\$path:$usb:g
echo 'Path $path is it!' | sed -r s:\\\$path:$usb:g
echo 'Path $path is it!' | sed -r s:'\$'path:$usb:g

enjoy!

Sven

-- 
Sven Guckes       sig-sed @guckes.net         GNU SED: 4.2.2   [2012-12-22]
SED Download:   ftp://ftp.gnu.org/gnu/sed/    SED FAQ: http://go.to/sed-faq
SED One-Liners: http://sed.sf.net/sed1line.txt SEDSED: http://sedsed.sf.net
SED   HomePage: http://www.gnu.org/directory/sed.html