#!/bin/bash
# sleep_log.sh - log the time remaining in a sleep

# this script can double as the body of a function
# I decided to go with the other approach, similar to python.

local 2>/dev/null d step

d=${1:-10} step=${2:-10}
if [ "$step" -gt "$d" ]; then
	step="$d"
fi
while [ "$d" -gt 0 ]; do
	echo -n "$d " >&2
	sleep "$step"
	d=$[d-step]
done
echo >&2

# return 2>/dev/null 0 || exit 0



#!/bin/bash
# sleep_log.sh - log the time remaining in a sleep

# I'm experimenting with sourceable functions, that we can also run directly.
# Another approach would be to keep the scripts as plain commands,
# and run a wrapper script to turn them into functions.

# Let's try that too!

# a shorthand for /dev/null would be nice

local 2>/dev/null d step

d=${1:-10} step=${2:-10}
if [ "$step" -gt "$d" ]; then
	step="$d"
fi
while [ "$d" -gt 0 ]; do
	echo -n "$d " >&2
	sleep "$step"
	d=$[d-step]
done
echo >&2


# return 2>/dev/null 0 || exit 0


