0003-ed.sh (884B)
1 #!/bin/sh 2 3 set -e 4 5 tmp1=tmp1.$$ 6 tmp2=tmp2.$$ 7 8 cleanup() 9 { 10 st=$? 11 rm -f $tmp1 $tmp2 12 exit $st 13 } 14 15 trap cleanup EXIT 16 17 cat <<EOF >$tmp1 18 foo 19 bar 20 21 baz 22 EOF 23 24 # Unspecified whether quit with a dirty buffer is considered an error, allow both 25 ../ed $tmp1 <<EOF >$tmp2 || test $? -eq 1 26 v#^\$#p 27 p 28 g/^\$/d 29 ,p 30 q 31 a 32 fizz 33 buzz 34 . 35 i 36 foobar 37 . 38 w 39 v!z\$!d 40 ,p 41 q 42 1,2j 43 1,2j 44 ,p 45 q 46 EOF 47 48 diff -u - $tmp2 <<EOF 49 13 50 foo 51 bar 52 baz 53 baz 54 foo 55 bar 56 baz 57 ? 58 29 59 baz 60 fizz 61 buzz 62 ? 63 bazfizzbuzz 64 ? 65 EOF 66 67 diff -u - $tmp1 <<EOF 68 foo 69 bar 70 baz 71 fizz 72 foobar 73 buzz 74 EOF 75 76 printf foo >$tmp1 77 ../ed $tmp1 <<EOF >$tmp2 78 ,p 79 w 80 EOF 81 82 # This is somewhat opinionated test for files without trailing newline, more 83 # documenting the current behavior, which differs from BSD and GNU eds. 84 diff -u - $tmp2 <<EOF || true 85 3 86 foo 87 4 88 EOF 89 90 diff -u - $tmp1 <<EOF 91 foo 92 EOF 93 94 ../ed <<EOF >$tmp2 95 i 96 foo 97 bar 98 . 99 ,t 100 1t 101 2t 102 2,3t 103 3,7p 104 EOF 105 106 diff -u - $tmp2 <<EOF 107 foo 108 bar 109 foo 110 bar 111 bar 112 EOF