Xref: utzoo comp.unix.xenix:6018 comp.unix.questions:13643 comp.unix.wizards:16167 Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!uwvax!tank!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.unix.xenix,comp.unix.questions,comp.unix.wizards Subject: SysV echo Keywords: rm cat mv regexp Message-ID: <17548@mimsy.UUCP> Date: 16 May 89 22:58:31 GMT References: <128@tdl.UUCP> <7170@bsu-cs.bsu.edu> <12970@ut-emx.UUCP> <536@visdc.UUCP> Distribution: usa Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 44 In article <536@visdc.UUCP> jiii@visdc.UUCP (John E Van Deusen III) writes: >Is there a particular SysV echo that is broken, or are you saying that >System V echo is broken, in general, because, in your opinion, it should >*not* do escape interpretation? The latter. (A separate program---printf(1)---should do escape interpretation.) The problem (which echo used to solve before it was changed in SysV or SysIII [when *did* it acquire interpretation, anyway?]) is this: suppose you are given a shell variable $foo, and need to echo it uninterpreted? There is a solution (albeit ugly): cat << end $foo end but you may need to do something more. To keep echo from munching away backslashes, you might do this: qfoo=`cat << end | sed 's/\\\\/\\\\\\\\' $foo end` except that, due to vagaries of Bourne's implementation, it does not work. (It might work in ksh.) So you get fancier: tf=${TMPDIR-/tmp}/quot$$; exec 3>$tf 4<$tf; rm $tf cat << end >&3 $foo end qfoo=`sed 's/\\\\/\\\\\\\\/g' <&4` exec 3>&- 4<&- and finally you have in $qfoo a version of $foo you can safely hand to echo(1). None of this would have been necessary if someone had simply added printf(1) instead of mucking with echo(1). Moreover, if you might want to run your script on (e.g.) V7, you will need a separate version without the extra quoting code. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris