Thanks for reply
I have seen the thread which you have mentioned
can you please explain briefly
d="20120103"
day=${d#??????}
temp=${d#????}
month=${temp%??}
year=${d%????}
I wont understand what is #??? refer to ?
These are parameter substitution that you can perform in any POSIX shell.
Here is the definition from Korn Shell manual:
${parameter#pattern}
${parameter##pattern}
If the shell pattern matches the beginning of
the value of parameter, the value of this
substitution is the value of the parameter
with the matched portion deleted; otherwise
the value of this parameter substituted. In
the former case, the smallest matching
pattern is deleted; in the latter case, the
largest matching pattern is deleted.
${parameter%pattern}
${parameter%%pattern}
If the shell pattern matches the end of the
value of parameter, the value of parameter
with the matched part is deleted; otherwise
substitute the value of parameter. In the
former, the smallest matching pattern is
deleted; in the latter, the largest matching
pattern is deleted.
So in day=${d#??????}
matches 6 characters from beginning and is deleted.
I hope this helps.
It might be a good alternative: return 0 for Sunday, 1 for Monday etc.
echo "(6 - $( cal $MM $YY | awk 'NR==3' |wc -w ) + ( $DD % 7 ) ) %7" | bc