[darcs-devel] darcs patch: work around backslash problem in test scripts for bett...

Ralph Corderoy ralph at inputplus.co.uk
Thu Apr 28 02:53:33 PDT 2005


Hi Tommy,

> On Thu, Apr 28, 2005 at 02:03:23AM +0100, Ian Lynagh wrote:
> > On Wed, Apr 27, 2005 at 05:28:20PM +0200, ptp at lysator.liu.se wrote:
> > > 
> > > hunk ./tests/directory_confusion.sh 24
> > >  echo altered_text > d/e/afile.txt
> > >  $DARCS record --author me --all --no-test --patch-name confusion
> > >  test ! -f _darcs/current/afile.txt
> > > -echo -e "y\nd\ny" | $DARCS unrecord
> > > +echo "y#d#y" | tr '#' '\n' | $DARCS unrecord
> > 
> > Does
> > 
> >     printf "foo\nbar\n"
> > 
> > not work for anyone? I think that would be cleaner.

printf isn't portable.  I agree GHC isn't portable either but we may as
well have the test scripts run on a wide range of shells.

> My problem was that the built in echo in dash echoed the -e option
> verbatim.
> 
> So I checked on echo in the autobook section about portable Bourne
> shell scripting, and it said backslashes should be avoided...
> 
> But now I checked again, and I stopped reading too early the first
> time.  Sorry about that.  It says: "try to avoid backslashes in echo
> arguments unless they are expanded by the shell".  The problem is only
> how to get _unexpanded_ backslashes in echo arguments.

You are getting unexpanded \n by using ".  The problem is you want
something to turn the two characters \n into ASCII LF.  Shell or echo
you don't care.

    $ echo a\nb "a\nb" 'a\nb'
    anb a\nb a\nb

One way is to use a sub-shell and multiple echos.

    $ (echo a; echo b)
    a
    b

But the neater, *portable*, way is to use tr to transliterate.  But some
trs don't know about \n meaning ASCII LF.  However, all trs support
three digit octal.  So...

    $ echo a/b | tr / \\012
    a
    b

Cheers,


Ralph.





More information about the darcs-devel mailing list