ZTree.com  | ZEN  | About...  

 Index   Back

Set quoting   [OT]

By: Ben Kent       
Date: Jan 12,2023 at 09:17
In Response to: [OT] Example BAT script (Slobodan Vujnovic)

> If you can't wrap your mind around nested FOR loops, this can
> get you started. By the way, I've never seen such use of double
> quotes in the SET command.


When I first saw the [set "var=%1"] syntax at work some years ago, I thought it was an error. So I did some investigating and it's valid syntax. So now I know of that syntax I use it in new scripts.


This puts quotes in the environment variable, which can make using the value difficult if you need to combine strings
Set var="%1"

So sometimes you have to do things like this, to get rid of the spare quotes
dir "c:\SomeDir\%var:"=%"

This sets the value without the quotes, which can make using the value easier
Set "var=%1"

The usage is simpler
dir "c:\SomeDir\%var%"



Messages in this Thread

96,640 Postings in 12,231 Threads, 350 registered users, 54 users online (0 registered, 54 guests)
Index | Admin contact |   Forum Time: Apr 12, 2024 - 2:23 pm UTC  |  Hits:62,817,800  (13,331 Today )
RSS Feed