Quoting a way from here:
for last; do : ; done
echo "${last}"
The last argument passed to the script would be stored in the variable last
.
As mentioned in the link, this would work in POSIX-compatible shells it works for ANY number of arguments.
BTW, I doubt if your script works the way you've written in your question:
var1 = `echo "$#"`
You need to remove those spaces around =
, i.e. say:
var1=`echo "$#"`
or
var1=$(echo "$#")