2bc9c893698df67c4af369d667f8c758c6bfda13
[platform/upstream/coreutils.git] / tests / misc / nl
1 #!/bin/sh
2 # exercise nl functionality
3
4 if test "$VERBOSE" = yes; then
5   set -x
6   nl --version
7 fi
8
9 pwd=`pwd`
10 t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$
11 trap 'status=$?; cd $pwd; chmod -R u+rwx $t0; rm -rf $t0 && exit $status' 0
12 trap '(exit $?); exit $?' 1 2 13 15
13
14 framework_failure=0
15 mkdir -p $tmp || framework_failure=1
16 cd $tmp || framework_failure=1
17
18 if test $framework_failure = 1; then
19   echo "$0: failure in testing framework" 1>&2
20   (exit 1); exit 1
21 fi
22
23 fail=0
24
25 echo a | nl > out || fail=1
26 echo b | nl -s%n >> out || fail=1
27 echo c | nl -n ln >> out || fail=1
28 echo d | nl -n rn >> out || fail=1
29 echo e | nl -n rz >> out || fail=1
30 echo === >> out
31 printf 'a\n\n' | nl > t || fail=1; cat -A t >> out
32 cat <<\EOF > exp
33      1  a
34      1%nb
35 1       c
36      1  d
37 000001  e
38 ===
39      1^Ia$
40        $
41 EOF
42
43 cmp out exp || fail=1
44 test $fail = 1 && diff out exp 2> /dev/null
45
46 (exit $fail); exit $fail