SysV echo
Chris Torek
chris at mimsy.UUCP
Sat May 20 16:03:36 AEST 1989
In article <541 at visdc.UUCP> jiii at visdc.UUCP (John E Van Deusen III) writes:
>For all purists who are almost certainly destined to be dragged into the
>SysV world kicking and screaming, let us formalize this solution as the
>command eucho.
I like it. :-)
(Incidentally, V8 offers a solution, not particularly pretty, but it does
work.)
>Actually SysV echo does not munch all backslashes, only ones it finds
>to its liking; echo '\f\g\h' will output <ff>\g\h<cr>. Is this
>unreasonable?
It is at least surprising (to one who knows C and other Unix languages).
>The shell, sh(1), also has an inconsistent appetite for back slashes.
Nay, not so:
> foo=FOO
> echo \$foo => $foo
> echo `echo \$foo` => FOO
>
>In the second case the backslash was removed as a special treat, because
>the expression was contained within accents grave.
The shell is entirely consistent: one backslash is interpreted each
time an expression is evaluated. Backquotes cause one additional
evaluation. The sequence is in fact
0. eval: echo \$foo (backslash quotes the $, so:)
1. run: echo $foo (with output to pipe)
2. output is: $foo
3. splice output
4. command is now: echo $foo => FOO (do variable substition)
5. run: echo FOO => FOO (output to stdout now)
6. output is: FOO => FOO
To prevent this, you want step 3 to see output in step 2 of the
form `\$foo', which can be produced with
eval `echo \\\$foo` => FOO
in 4BSD---this causes step 0 to see
echo \\\$foo
which makes step 1 pass the argument
\$foo
to echo. If \$ is special in SysV echo (my guess now: it is not),
you will have to pass two backslashes to it rather than one---make
the argument `\\$foo'---which requires typing the command
eval `echo \\\\\$foo` => FOO
If \$ is not special to a SysV echo, the BSDish version will work too.
(One hopes that at least \\ becomes \ in SysV echo.)
--
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain: chris at mimsy.umd.edu Path: uunet!mimsy!chris
More information about the Comp.unix.wizards
mailing list