#!/bin/bash shopt -s extglob export TIMEFORMAT="(%U + %S) / %R : %P " strings=( now snow '@0' '2009-02-13 23:31:30 UTC' '2001-09-09 01:46:40 UTC' 'Sep 09 2001 UTC 01:46:39' 12:34:56 10/12 'Mar 25' 10:00 22:30 '7 Mon 12:00' 'Apr 1 12:34' 'Dec 31 23:59' 'Jan 1 00:00' '@1' 'tomorrow' 'yesterday' ) _sep=$' :\n' print2byLine() { printf "%-24s:%13s%s" "$1" "${2:(${#2}<14?0:${#2}-13)}" "${_sep%:*}" _sep="${_sep#*:}:${_sep%:*}" } multiforked() { local _string _out for _string in "${strings[@]}" ;do _out="$(date -d "$_string" +%s 2>&1)" print2byLine "$_string" "$_out" done printf "%-12s (%d dates): " ${FUNCNAME^^} ${#strings[@]} >&2 } oldForked() { local _dateOut _dateIn _string _out _fifo=/tmp/fifo-demo-$$ mkfifo $_fifo exec 9> >(exec stdbuf -o0 date -f - +%s >$_fifo 2>&1) exec 8<$_fifo rm $_fifo for _string in "${strings[@]}" ;do echo >&9 $_string read -t 1 -u 8 _out print2byLine "$_string" "$_out" done exec 8<&- 9>&- printf "%-12s (%d dates): " ${FUNCNAME^^} ${#strings[@]} >&2 } forked() { local _dateOut _dateIn _string _out exec 8<> <(:) exec 9> >(exec stdbuf -o0 date -f - +%s >&8 2>&8) for _string in "${strings[@]}" ;do echo >&9 $_string read -t 1 -u 8 _out print2byLine "$_string" "$_out" done exec 8<&- 9>&- printf "%-12s (%d dates): " ${FUNCNAME^^} ${#strings[@]} >&2 } time multiforked time oldForked time forked