You can create and use environment variables with names that begin with a digit, but it is not a good idea, and should be avoided. Defining the variable is no problem. But expansion using normal percent expansion is a problem.
The problem is the batch parser sees the inital %1
in %1word%
and expands the first argument instead of the variable. Even if no argument was passed, it still expands the non-existent first argument into an empty string. The rules are explained at https://stackoverflow.com/a/4095133/1012053 and https://stackoverflow.com/a/7970912/1012053.
You can access the variable using delayed expansion instead.
Here is an example script that demonstrates the issues:
@echo off
setlocal enableDelayedExpansion
set "1var=Environment variable value."
call :test "Argument 1 value"
exit /b
:test
echo arg 1 = %1
echo 1var normal = %1var%
echo 1var delayed = !1var!
-- Sample Output --
arg 1 = "Argument 1 value"
1var normal = "Argument 1 value"var
1var delayed = Environment variable value.
Note that argument expansion of the form %1
is only an issue within a batch script - it is not relevant to commands issued in a command prompt (non batch) context. So you could define 1word from the command prompt and then echo %1word%
would work fine from the command prompt.
Because of the complexities, the moral of the story is - "don't use variable names that begin with a digit".