ZTree.com  | ZEN  | About...  

 Index   Back

[OT] Example BAT script   [OT]

By: Liviu       
Date: Jan 13,2023 at 06:24
In Response to: [OT] Example BAT script (Slobodan Vujnovic)

> [...] By the way, I've never seen such use of double quotes in the SET command.

In addition to Ben's well taken points, the quotes also allow assigning values that contain cmd "poison" characters.

> set "dir=%cd%"

Suppose the above gets called while the current directory is "C:\etc\a^b&c", then this happens:

C:\etc\a^b&c>set dir=%cd%
'c' is not recognized as an internal or external command,
operable program or batch file.

C:\etc\a^b&c>echo %dir%
C:\etc\ab

C:\etc\a^b&c>set "dir=%cd%"

C:\etc\a^b&c>echo "%dir%"
"C:\etc\a^b&c"


Cheers,
Liviu

310 views      
 

Messages in this Thread

 
96,637 Postings in 12,231 Threads, 350 registered users, 87 users online (0 registered, 87 guests)
Index | Admin contact |   Forum Time: Mar 29, 2024 - 1:03 am UTC  |  Hits:62,386,714  (1,500 Today )
RSS Feed