b53864ef58c2551b140fe0a3b11481ad3950079a
[platform/upstream/coreutils.git] / tests / misc / cat-proc
1 #!/bin/sh
2 # Ensure that cat -E produces same output as cat, module `$'s,
3 # even when applied to a file in /proc.
4
5 if test "$VERBOSE" = yes; then
6   set -x
7   cat --version
8 fi
9
10 pwd=`pwd`
11 t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$
12 trap 'status=$?; cd $pwd; chmod -R u+rwx $t0; rm -rf $t0 && exit $status' 0
13 trap '(exit $?); exit $?' 1 2 13 15
14
15 framework_failure=0
16 mkdir -p $tmp || framework_failure=1
17 cd $tmp || framework_failure=1
18
19 if test $framework_failure = 1; then
20   echo "$0: failure in testing framework" 1>&2
21   (exit 1); exit 1
22 fi
23
24 f=/proc/cpuinfo
25 test -f $f \
26   || {
27        echo "$0: no $f skipping this test" 1>&2
28        (exit 77); exit 77
29      }
30
31 fail=0
32
33 # Yes, parts of /proc/cpuinfo might change between cat runs.
34 # If that happens, consider choosing a file that's less likely to change,
35 # or just filter out the changing lines.  The sed filter should help
36 # to avoid any spurious numeric differences.
37 cat -E $f | sed 's/[0-9][0-9]*/D/g' | tr -d '$' > out || fail=1
38 cat    $f | sed 's/[0-9][0-9]*/D/g' | tr -d '$' > exp || fail=1
39
40 cmp out exp || fail=1
41 test $fail = 1 && diff out exp 2> /dev/null
42
43 (exit $fail); exit $fail