How the below command works?

hi,
can any one explain the below command. run it and see and if you understand please tell me.

File=s1_abc.txt.xls.pdf
MOD_File=$(echo ${File%.*}_`date +%Y%m%d_%H%M%S%N`.${File##*.})

i asked somedays before and got the above code. i needed to add date time stamp just before the last extension of the filename.

if i use the below command, it removes the last extension from the filename

echo ${File%.*}

output is:
s1_abc.txt.xls

if i use echo ${File%.*.*} , it removes the last two extensions

output is:
s1_abc.txt

echo ${File##*.} gives me the last extension i.e. pdf

echo ${File#*.} gives me all the extension i.e. txt.xls.pdf

how the above command works especially % and #

You pretty much described it yourself. % and # are pattern-matching-and-delete-operators.

${variable#pattern} and ${variable##pattern} ... if pattern matches the beginning of the value of variable , then the expression is the value of the variable with the matched portion deleted. If there is no match, the expression is the entire value of the variable. With one # , the smallest matching pattern is deleted, with two ## the largest.

The % operator does the same at the end of the variable.

# - remove prefix pattern
% - remove suffix pattern

see discussion on parameter expansion in man bash or man ksh for more info ...