aboutsummaryrefslogtreecommitdiff
path: root/bin/fnl
blob: 6969665be010c5904ab48538550b277ea131c73e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/bin/sh
# Run a command and save its output and error to temporary files

# Check we have at least one argument
if [ "$#" -eq 0 ] ; then
    printf >&2 'fnl: Command needed\n'
    return 2
fi

# Create a temporary directory; note that we *don't* clean it up on exit
dir=$(mktd fnl) || exit

# Run the command; keep its exit status
{ "$@" ; } >"$dir"/stdout 2>"$dir"/stderr
ret=$?

# Run wc(1) on each of the files
wc -- "$dir"/*

# Exit with the wrapped command's exit status
exit "$ret"