On Thu, Feb 21, 2019 at 1:47 AM Andreas Schwab <sch...@suse.de> wrote:
>
> On Feb 20 2019, Ian Lance Taylor <i...@golang.org> wrote:
>
> >               if test x$hasoutput = xtrue; then
> > -                 echo '      {"'$n'", '$j', "'"$output"'", '$unordered'},'
> > +                 echo '      {"'$n'", '$j', "'"$(cat example2.txt)"'", 
> > '$unordered'},'
>
> That still has a problematic echo with backslashes.

How does this version look?  Does it fix the problem?

Ian
commit fb0d3e611050e5884cbe6290c6def24b8b42b23d
Author: Ian Lance Taylor <i...@golang.org>
Date:   Wed Feb 20 17:45:44 2019 -0800

    gotest: avoid using echo inside $()
    
    The handling of newlines is not portable between bash and ksh.
    
    Change-Id: I31cf57c9b2bcf98e8390ab92b75565a6798872de

diff --git a/libgo/testsuite/gotest b/libgo/testsuite/gotest
index 06000eae..c9c14652 100755
--- a/libgo/testsuite/gotest
+++ b/libgo/testsuite/gotest
@@ -619,21 +619,25 @@ symtogo() {
                    # Turn pairs of spaces into " \x20", because $() will
                    # drop duplicate spaces.
                    # Drop trailing spaces, and turn newlines into \n.
-                   output="$(sed '1 s/\([Uu]nordered \)\?[Oo]utput:[   ]*//' < 
example.txt |
+                   # Remove leading and trailing \n.
+                   sed '1 s/\([Uu]nordered \)\?[Oo]utput:[     ]*//' < 
example.txt |
                                 sed -e 's/\\/\\\\/g' \
                                     -e 's/"/\\"/g' \
                                     -e 's/     /\\t/g' \
                                     -e 's/  / \\x20/g' \
                                     -e 's/[    ]*$/\\n/g' |
-                                tr -d '\n')"
-                   # Remove leading and trailing \n.
-                   output="$(echo "$output" | sed -e 's/^\(\\n\)*//' -e 
's/\(\\n\)*$//')"
+                                tr -d '\n' |
+                                sed -e 's/^\(\\n\)*//' \
+                                    -e 's/\(\\n\)*$//' > example2.txt
                    hasoutput=true
                    rm -f example.txt
                    break
                done
                if test x$hasoutput = xtrue; then
-                   echo '      {"'$n'", '$j', "'"$output"'", '$unordered'},'
+                   echo '      {"'$n'", '$j','
+                   sed -e 's/^/                "/' -e 's/$/", /' < example2.txt
+                   echo $unordered'},'
+                   rm -f example2.txt
                fi
        done
        echo '}'

Reply via email to