logo

The meaning of the tilde in the input parameters of the batch command 📂Programing

The meaning of the tilde in the input parameters of the batch command

Overview

When receiving input parameters for a batch command, the tilde symbol as in %1 and %~1 determines whether or not to remove double quotes " from the input1.

Code

For instance, let’s say there’s an RPEL.bat file written as follows.

@echo off

echo %1 > result.txt
echo %~1 >> result.txt
pause

When you execute it with the input parameter "space bar" which includes spaces, you obtain the following result.

PS C:\admin> .\REPL.bat "space bar"
계속하려면 아무 키나 누르십시오 . . .

alt text

The first echo recorded %1 as it is, while the second echo recorded only the string with removed double quotes.

Environment

  • OS: Windows11