Xref: utzoo comp.unix.xenix:6072 comp.unix.questions:13750 comp.unix.wizards:16237 Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!uxc!tank!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.unix.xenix,comp.unix.questions,comp.unix.wizards Subject: Re: SysV echo Message-ID: <17638@mimsy.UUCP> Date: 20 May 89 06:03:36 GMT References: <128@tdl.UUCP> <7170@bsu-cs.bsu.edu> <12970@ut-emx.UUCP> <541@visdc.UUCP> Distribution: usa Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 63 In article <541@visdc.UUCP> jiii@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 \g\h. 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@mimsy.umd.edu Path: uunet!mimsy!chris