[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference turris::digital_unix

Title:DIGITAL UNIX(FORMERLY KNOWN AS DEC OSF/1)
Notice:Welcome to the Digital UNIX Conference
Moderator:SMURF::DENHAM
Created:Thu Mar 16 1995
Last Modified:Fri Jun 06 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:10068
Total number of notes:35879

8622.0. "What's so special about \E?" by CPEEDY::VATNE (Peter Vatne, PATHWORKS for UNIX Server Engineering) Tue Jan 28 1997 16:22

Can anyone explain this strange shell behavior?  This is on Digital Unix 4.0a.
(I admit to being a complete Unix novice, but this is just too weird...)

$ cat e.sh
cat > dump << EOT
This is \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z.
This is \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z.
This is the \End
EOT
cat dump

$ csh e.sh
This is \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z.
This is \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z.
This is the \End

$ ksh e.sh
This is \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z.
This is \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z.
This is the \End

$ sh e.sh
This is \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z.
This is \A\B\C\DE\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z.
This is the End

What is so special about \E to the Bourne shell??
T.RTitleUserPersonal
Name
DateLines
8622.1EOF escapee.. work-a-round (if that's what you need)COMEUP::SIMMONDSlock (M); while (not *SOMETHING) { Wait(C,M); } unlock(M)Tue Jan 28 1997 22:3716
    No explanation, just a workaround for you..  in e.sh, change
    
    cat > dump << EOT
    [...]
    EOT
    
       to
    cat > dump << =EOT=
    [...]         ^
    =EOT=         |
    ^             |
    |             |
    (e.g. some character at this position which is _not_ in
     the set that you're Escaping)
    
    John.
8622.2looks like a gray areaNETRIX::&quot;[email protected]&quot;Farrell WoodsWed Jan 29 1997 10:2926
Usually the backslash is used to "escape" the next character.  That is,
if the character would normally have some special meaning then the
backslash says that the following character should be accepted literally.

One might use that feature to embed dollar signs into strings for instance,
since normally things that begin with dollar signs are considered to be
variable names.  Now if you need a literal backslash somewhere you can still
escape that with a backslash, as in "\\".

The scanner has to look for these (among other things) when considering
how to tokenize the shell's input.  I'm not sure if there was ever any
formal rule that said what to do if the character following the backslash
did not have any special meaning in the first place.  It would appear that
the shells pass the backslash and the following character and do not swallow
the backslash.  (Try this: instead of using \a\b\c\d etc. in your examples,
use \\a\\b\\c etc.  I think you'll find that in this case, the Bourne shell
will do what you expect.)

As .1 points out, the "end of input" token that you defined begins with
the letter E.  No doubt the Bourne shell's scanner dropped the backslash
while trying to see if it had the token "EOT", or something different.


	-- Farrell
 
[Posted by WWW Notes gateway]
8622.3Thanks!CPEEDY::VATNEPeter Vatne, PATHWORKS for UNIX Server EngineeringWed Jan 29 1997 11:183
Thanks for the workaround!  It is definitely the interaction between the
first letter of the "termination string" and escaped characters in the
input stream.  We'll incorporate the workaround.