• Please review our updated Terms and Rules here

Referencing argument with spaces in MS-DOS 3.3 batch file?

charnitz

Experienced Member
Joined
Nov 17, 2020
Messages
55
Location
North America
batch.bat contains this:

@echo %1​

Results:

C>batch hello
hello

C>batch hello string
hello

C>batch "hello string"
"hello​

How can the batch file reference an argument with spaces in it?

This pattern concatenates arguments, but runs out of argument variables after 8 spaces between 9 strings:

set msg=%1 %2
echo %msg%​
 
You can use the SHIFT subcommand to access more than 9 parameters.

I can't remember if DOS 3.3 has %0 set as the whole of the trailing string. e.g. echo %0
 
An example of using SHIFT

@ECHO OFF
SET msg=
:REDO
IF '%1'=='' GOTO END
ECHO %1
SET msg=%msg% %1
SHIFT
GOTO REDO
:END
ECHO %msg%
 
Back
Top