File: example.buffer

package info (click to toggle)
shellia 5.3.2
  • links: PTS
  • area: main
  • in suites: buster
  • size: 412 kB
  • sloc: sh: 3,235; makefile: 32
file content (69 lines) | stat: -rwxr-xr-x 1,322 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/sh
# vim: set filetype=sh :
#        file: example.buffer
#   copyright: Bernd Schumacher <bernd.schumacher@hpe.com> (2007-2018)
#     license: GNU General Public License, version 3
# description: test if we get unbuffered stdout, stderr, and logfile output.
#
#    see also: test.buffer
set -e
set -u

# prefer local copy
[ -f ia ] && . ./ia || . /usr/share/shellia/ia
eval "$ia_init"

cmds="cat|ia_out|ia_logout|ia_logerr"
usage()
{
  cat <<END >&2
ERROR: $1

Usage: t1 [--sleep <sleep>] [--exit] $cmds
  --sleep <sleep> - sleep <sleep> seconds between printing the numbers 1 to 5
  --exit          - exit after printing 4 numbers
END
  exit 1
}

run()
{
  for i in $(seq 5); do
     echo "$i"
     if [ "$ex" ] && [ "$i" = "4" ]; then
       exit 1
     fi
     sleep $sleep
  done | $cmd
}

sleep=1
ex=""
cmd=""
check=""
while [ $# -ge 1 ]; do
  if [ "$(echo "|$cmds|" | grep "|$1|")" ]; then
    cmd="$1"
  elif [ "$1" = "--exit" ]; then
    ex="$1"
  elif [ "$1" = "-c" ]; then
    check="$1"
  elif [ "$1" = "-C" ]; then
    check="$1"
  elif [ "$1" = "--sleep" ]; then
    sleep="$2"
    shift
  else
    usage "Unknown <$1>"
  fi
  shift
done
[ "$cmd" ] || usage "No option $cmds given"

if [ "$check" = "-c" ]; then
  ia_stdout ".*"
elif [ "$check" = "-C" ]; then
  ia_ignore ".*"
fi
ia_add run
ia $check