#!/bin/sh

stamp=$(date '+%s')
outfile=$(mktemp "${TMPDIR:-/tmp}"/args"${stamp}")
trap 'rm -f -- "$outfile"' EXIT HUP INT TERM
# echo "dot - graphviz version 5.0.1 (0)" >&2
{
  echo "$# Args: ${*:-DEFAULT}"
  # echo "Starred: $*"
  # echo "${@:-default}" | sed 's/\w\+/\0-w/g'
  for last; do
    true
  done
  echo "Last arg: ${last}"
} | tee "${outfile}"

# `tty -s` deprecated in favor of `test -t 0`
if test -t 0 || test "$1" = "-V"; then
  echo "Not reading from stdin"
else
  tee "${outfile-stdin}"
fi
