POSIXly (-d
is not a standard date
option. When available, it means something different to different implementations), to give the day name in the user's locale, Sunday being either 0 or 7:
getdayname() (
IFS=';'
set -o noglob
days=$(locale day) || exit
for day do
set -- $days $days
shift "$day" &&
printf '%s\n' "$1"
done
)
Examples:
$ getdayname 0 4 7
Sunday
Thursday
Sunday
$ LANG=es_VE.UTF-8 getdayname 0 4 7
domingo
jueves
domingo
With GNU or busybox date
(whose -d ...
doesn't support relative dates), or ast-open date
(whose -d ...
supports relative dates but in a different way from GNU's date
):
getdayname() (
for day do
date -ud "1970-01-$((day + 11))" +%A
done
)
With zsh
without external requirements:
$ zmodload zsh/langinfo
$ day=0
$ printf '%s\n' $langinfo[DAY_$((day+1))]
Sunday
Or:
$ zmodload zsh/datetime
$ day=0
$ TZ=UTC0 strftime %A $((86400 * (3+day)))
Sunday