In a batch file, how can I get the last token in a variable regardless of whether it is a number or a word and regardless of how many tokens/words there are in the variable.
If you insist on passing only a single argument, then you can use a subroutine:
@echo off
call :get_last %~1
echo.%last%
goto :eof
rem get_last tokens...
:get_last
set last=%1
shift
if [%1]==[] goto :eof
goto get_last
However, if you're just passing any number of arguments to the batch, then you can do that directly:
@echo off
:l
set last=%1
shift
if [%1]==[] goto pl
goto l
:pl
echo %last%
Side note: You rarely want to put exit in a batch file, as it exits the command processor, not the batch. That's kinda annoying if you use it directly from the shell or from other batch files.