#!/bin/sh set -eu indent='' le="$(printf '\n.')"; le="${le%.}" err() { local fmt="${1}" shift 1 printf "Error: ${fmt}\n" "${@}" 1>&2 return 0 } gen_indent() { local l=${1} shift 1 local i= i=0 while [ ${i} -lt ${l} ]; do indent="${indent} " i=$((${i} + 1)) done return 0 } do_df() { local sed_bre= sed_bre='^..* *..* *..* *..* *\([0-9][0-9]*%\) \(..*\)$' df -h -x devtmpfs -x tmpfs | \ sed "1d; s/${sed_bre}/${indent}\\1 \\2/;" | tr '\n' "${le}" return 0 } do_uptime() { local up= local idle= local min= local hr= local day= read -r up idle 0]\n' "${0}" printf '\n' printf 'Options:\n' printf ' -i Indent lines with spaces\n' printf ' -r Print carriage returns instead of line feeds\n' return 0 } main() { local opt= while getopts 'i:r' opt "${@}"; do case "${opt}" in 'i') case "${OPTARG}" in *[!0-9]* | '') usage 1>&2 return 1 esac gen_indent ${OPTARG} ;; 'r') le="$(printf '\r.')"; le="${le%.}";; '?') usage 1>&2 return 1 ;; esac done shift $((${OPTIND} - 1)) if [ ${#} -ne 0 ]; then usage 1>&2 return 1 fi do_df do_uptime return 0 } main "${@}"