When i'm changing dates in your script i have wrong solutions. Or maybe i'm doing something wrong?musher0 wrote:What do you think?
I made another versions. Not short like Mochi's (Hail to the Caesar ):
1.
Code: Select all
#!/bin/sh
#shorter version of my earlier script
day=$1
month=$2
year=$3
# array with names of days
nod=($(cal $month $year | head -2 | tail -1))
# number of days in week that include $day
cdiw=$(cal $month $year | grep -w $day | wc -w)
# number of days in week before $day
dbd=$(($(cal $month $year | grep -w "$day" | tr ' ' '\n' | grep -wB 7 "$day" | wc -w)-1))
if (( $cdiw < 7 )) && (( $day < 7 ));
then
echo "$day/$month/$year is ${nod[7-$cdiw + $dbd]}"
else
echo "$day/$month/$year is ${nod[dbd]}"
fi
Code: Select all
#!/bin/sh
# idea of use pr command
day=$1
month=$2
year=$3
# vertical list of week names
n=$(cal $month $year | head -2 | tail -1 | tr ' ' '\n')
# store whole week which include $day
k=$(cal $month $year | tail -n +3 | grep -w $day)
# Mochi's stuff, strip 3 spaces and 2 spaces to 1 space
k=${k// / }
k=${k// / }
# vertical list of week which include $day
k=$(echo "$k" | tr ' ' '\n')
#vertical lists $n and $k together
dow=$(echo -e "$n\n$k" | pr -t -s" " --column 2 | grep -w $day)
echo "$dow/$month/$year"