Re: How do implement this wildcard?
- From: "Pegasus [MVP]" <news@xxxxxxxxxxxxx>
- Date: Thu, 23 Apr 2009 13:49:18 +0200
"Synapse Syndrome [KGB]" <synapse@xxxxxxxxxxxxxxxxxxxx> wrote in message
news:OICNLPAxJHA.5516@xxxxxxxxxxxxxxxxxxxxxxx
Pegasus [MVP] <news@xxxxxxxxxxxxx> wrote:
I want a .cmd script to check that %1 is a UNC server name and goto
something else.
You can probably see what I want to do, so how do I do it correctly?
if [%1] == [\\*] goto:UNC
Here you go:
@echo off
set parm=%1x
if [%parm:~0,2%]==[\\] echo UNC
Ah, thanks a lot Pegasus. Got it working now, but I do not really know
what that does. Like what is that x supposed to mean? I have read about
this method of spoofing wildcards, by making environmental variables,
before, but it was not explained in any way that I could understand. Have
you got any link that explain this?
The temporary variables disappear once that CMD instance is closed, right?
Or is there a way to clean them up at the end of the script?
The "x" makes the script robust so that it does not fail in the line below
in case you invoke it without a parameter. Any character or string would do,
e.g. set parm=%1Synapse
My script does not really "spoof" wildcards - it merely uses the substring
function available at the console. Since the substring function only works
for environmental variables (at least as far as I know), the script must
assign %1 to an environmental variable.
Every process, whether it is a Command Processor or some other executable,
inherits its environmental variables from the parent that invokes it. When
that process closes then all variables are lost. You need to execute a
special command if you wish to preserve a variable and make it available for
other processes.
.
- Follow-Ups:
- Re: How do implement this wildcard?
- From: Al Dunbar
- Re: How do implement this wildcard?
- References:
- How do implement this wildcard?
- From: Synapse Syndrome [KGB]
- Re: How do implement this wildcard?
- From: Pegasus [MVP]
- Re: How do implement this wildcard?
- From: Synapse Syndrome [KGB]
- How do implement this wildcard?
- Prev by Date: Re: Logon script help
- Next by Date: Re: Logon script help
- Previous by thread: Re: How do implement this wildcard?
- Next by thread: Re: How do implement this wildcard?
- Index(es):
Relevant Pages
|