|
server
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How do implement this wildcard?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 Cheers ss. "Synapse Syndrome [KGB]" <synapse@NOSPAMsyndrome.me.uk> wrote in message Here you go:news:u6qDJd$wJHA.1300@TK2MSFTNGP05.phx.gbl... >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 > @echo off set parm=%1x if [%parm:~0,2%]==[\\] echo UNC Pegasus [MVP] <n***@microsoft.com> wrote:
> Ah, thanks a lot Pegasus. Got it working now, but I do not really know what >> 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 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? Cheers ss.
Show quote
Hide quote
"Synapse Syndrome [KGB]" <synapse@NOSPAMsyndrome.me.uk> wrote in message The "x" makes the script robust so that it does not fail in the line below news:OICNLPAxJHA.5516@TK2MSFTNGP02.phx.gbl... > Pegasus [MVP] <n***@microsoft.com> 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? 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.
Show quote
Hide quote
"Pegasus [MVP]" <n***@microsoft.com> wrote in message The script determines whether or not the parameter is a UNC, but it is not news:OIR5DmAxJHA.3832@TK2MSFTNGP02.phx.gbl... > > "Synapse Syndrome [KGB]" <synapse@NOSPAMsyndrome.me.uk> wrote in message > news:OICNLPAxJHA.5516@TK2MSFTNGP02.phx.gbl... >> Pegasus [MVP] <n***@microsoft.com> 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. necessarily a "UNC server name", as originally requested. Whether a UNC string is completely valid as in \\server\share or \\server\share\path\file.ext or partly valid as in \\server would be significantly more difficult to determine using batch alone. That said, the specific requirements might not require a completely rigorous solution. Another technique that might be useful here applies to batch script parameters andFOR loop variables. For example the output from this statement: for %%F in (C:\whatever.txt x.y \\server) do echo/[%%~dF] should be: [C:] [C:] [\\] In otherwords, the "drive" component of a UNC is the leading "\\". /Al Al Dunbar <aland***@hotmail.com> wrote:
> Yes, it's fine for my needs.> The script determines whether or not the parameter is a UNC, but it is > not necessarily a "UNC server name", as originally requested. Whether a > UNC string is completely valid as in \\server\share or > \\server\share\path\file.ext or partly valid as in \\server would be > significantly more difficult to determine using batch alone. That said, > the specific requirements might not require a completely rigorous > solution. > Another technique that might be useful here applies to batch script The FOR command is the one thing that I have not ever been able to > parameters andFOR loop variables. For example the output from this > statement: > > for %%F in (C:\whatever.txt x.y \\server) do echo/[%%~dF] > > should be: > > [C:] > [C:] > [\\] > > In otherwords, the "drive" component of a UNC is the leading "\\". understand however many times I try. ss. "Synapse Syndrome [KGB]" <synapse@NOSPAMsyndrome.me.uk> wrote in message There are several flavours for the "for" command. Let me show you some of news:u3Xo7Y0xJHA.6004@TK2MSFTNGP02.phx.gbl... > The FOR command is the one thing that I have not ever been able to > understand however many times I try. > > ss. them. They all work from the Command Prompt. for %a in (Synaps Syndrome [KGB]) do @echo %a Here the "for" command looks at each item inside the brackes and assigns it to the variable %a. I then chose to echo that variable to the console screen. for /L %a in (10, 1, 20) do @echo %a Here I use the /L switch so that the "for" command works as a counter. It will assign values from 10 to 20 to the variable %a. for %a in (c:\windows\*.*) do @echo %a Here we have a whole collection of files inside the bracket. The variable %a will be set to the name of each of them in turn, one at a time. This is just scratching the surface. I suggest you play with the above commands, then move on to more demanding variations. You can see all of them when you type for /? at the Command Prompt. Pegasus [MVP] <n***@microsoft.com> wrote:
Show quoteHide quote > Thanks. I have tried returning to this matter a few times over the last few >> The FOR command is the one thing that I have not ever been able to >> understand however many times I try. >> > There are several flavours for the "for" command. Let me show you some of > them. They all work from the Command Prompt. > > for %a in (Synaps Syndrome [KGB]) do @echo %a > Here the "for" command looks at each item inside the brackes and assigns > it to the variable %a. I then chose to echo that variable to the console > screen. > > for /L %a in (10, 1, 20) do @echo %a > Here I use the /L switch so that the "for" command works as a counter. It > will assign values from 10 to 20 to the variable %a. > > for %a in (c:\windows\*.*) do @echo %a > Here we have a whole collection of files inside the bracket. The > variable %a will be set to the name of each of them in turn, one at a > time. > > This is just scratching the surface. I suggest you play with the above > commands, then move on to more demanding variations. You can see all of > them when you type for /? at the Command Prompt. > weeks, but I have not got that much further than your examples. :/ Are there any other ways of defining the set? I would find it very helpful if I could make a set out of a list in a text file. ss. Synapse Syndrome [KGB] <synapse@NOSPAMsyndrome.me.uk> wrote:
Show quoteHide quote >> I have even been using this in batch files, to capitalise parameters, but I >>> The FOR command is the one thing that I have not ever been able to >>> understand however many times I try. >>> >> There are several flavours for the "for" command. Let me show you some >> of them. They all work from the Command Prompt. >> >> for %a in (Synaps Syndrome [KGB]) do @echo %a >> Here the "for" command looks at each item inside the brackes and assigns >> it to the variable %a. I then chose to echo that variable to the >> console screen. >> >> for /L %a in (10, 1, 20) do @echo %a >> Here I use the /L switch so that the "for" command works as a counter. >> It will assign values from 10 to 20 to the variable %a. >> >> for %a in (c:\windows\*.*) do @echo %a >> Here we have a whole collection of files inside the bracket. The >> variable %a will be set to the name of each of them in turn, one at a >> time. >> >> This is just scratching the surface. I suggest you play with the above >> commands, then move on to more demanding variations. You can see all of >> them when you type for /? at the Command Prompt. >> > > Thanks. I have tried returning to this matter a few times over the last > few weeks, but I have not got that much further than your examples. :/ > > Are there any other ways of defining the set? I would find it very > helpful if I could make a set out of a list in a text file. > have no idea how it works: set parm=%1 for %%U in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do ( call set "parm=%%parm:%%U=%%U%%" ) ss.
Show quote
Hide quote
"Synapse Syndrome [KGB]" <synapse@NOSPAMsyndrome.me.uk> wrote in message This is a question that the boys in alt.msdos.batch.nt would love to dig news:eTK9pC96JHA.1564@TK2MSFTNGP06.phx.gbl... > Synapse Syndrome [KGB] <synapse@NOSPAMsyndrome.me.uk> wrote: >>> >>>> The FOR command is the one thing that I have not ever been able to >>>> understand however many times I try. >>>> >>> There are several flavours for the "for" command. Let me show you some >>> of them. They all work from the Command Prompt. >>> >>> for %a in (Synaps Syndrome [KGB]) do @echo %a >>> Here the "for" command looks at each item inside the brackes and assigns >>> it to the variable %a. I then chose to echo that variable to the >>> console screen. >>> >>> for /L %a in (10, 1, 20) do @echo %a >>> Here I use the /L switch so that the "for" command works as a counter. >>> It will assign values from 10 to 20 to the variable %a. >>> >>> for %a in (c:\windows\*.*) do @echo %a >>> Here we have a whole collection of files inside the bracket. The >>> variable %a will be set to the name of each of them in turn, one at a >>> time. >>> >>> This is just scratching the surface. I suggest you play with the above >>> commands, then move on to more demanding variations. You can see all of >>> them when you type for /? at the Command Prompt. >>> >> >> Thanks. I have tried returning to this matter a few times over the last >> few weeks, but I have not got that much further than your examples. :/ >> >> Are there any other ways of defining the set? I would find it very >> helpful if I could make a set out of a list in a text file. >> > > I have even been using this in batch files, to capitalise parameters, but > I have no idea how it works: > > set parm=%1 > for %%U in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do ( > call set "parm=%%parm:%%U=%%U%%" > ) > > ss. their teeth into. It uses some convoluted command processor quirk for the Set command. When I need an upper/lower case function then I prefer to use the inbuilt UCase/LCase functions of VB Script. Pegasus [MVP] <n***@microsoft.com> wrote:
Show quoteHide quote >>> I see. I do not need to use the x in this case as the script starts with..>>>> 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 if [%1] == [] goto :help if [%1] == [/?] goto :help > My script does not really "spoof" wildcards - it merely uses the Thanks, with that keyword 'substring', I found this page which describes it > 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. all, and it is a lot easier to work out than I thought previously: http://www.ss64.com/nt/syntax-substring.html > Every process, whether it is a Command Processor or some other I suppose you mean ENDLOCAL, and SETX for permanent changes?> 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. Cheers ss. "Synapse Syndrome [KGB]" <synapse@NOSPAMsyndrome.me.uk> wrote in message <snip>news:e9MiGY0xJHA.1516@TK2MSFTNGP06.phx.gbl... > Thanks, with that keyword 'substring', I found this page which describes The concept of "substring" (sometimes called "midstring") is used > it all, and it is a lot easier to work out than I thought previously: > http://www.ss64.com/nt/syntax-substring.html extensively in most programming languages. It is often complemented by the "leftstring" and "rightstring" functions, both of which are available under the Windows Command Processor. Type for /? to see how it's done. Note that the syntax for these functions under the Command Processor is unbelievably cryptic. In most programming languages it is far simpler, e.g. x = mid(Name, 3, 5) y = left(Name, 2) z = right(Name, 9) > I suppose you mean ENDLOCAL, and SETX for permanent changes? When you run a batch file such as@echo off set Name=ss then the variable %Name% remains set within the current Command Processor. When you modify this batch file like so: @echo off setlocal set Name=ss endlocal then the variable %Name% is lost the moment the batch file ends. In either case the variable is lost when the current Command Processor is closed. To prevent this, you can use setx.exe. I recommend you test these concepts in order to become comfortable with them. Pegasus [MVP] <n***@microsoft.com> wrote:
Show quoteHide quote > <snip> A belated thanks. I understand all that now.>> Thanks, with that keyword 'substring', I found this page which describes >> it all, and it is a lot easier to work out than I thought previously: >> http://www.ss64.com/nt/syntax-substring.html > > The concept of "substring" (sometimes called "midstring") is used > extensively in most programming languages. It is often complemented by > the "leftstring" and "rightstring" functions, both of which are > available under the Windows Command Processor. Type for /? to see how > it's done. Note that the syntax for these functions under the Command > Processor is unbelievably cryptic. In most programming languages it is > far simpler, e.g. x = mid(Name, 3, 5) > y = left(Name, 2) > z = right(Name, 9) > >> I suppose you mean ENDLOCAL, and SETX for permanent changes? > > When you run a batch file such as > @echo off > set Name=ss > > then the variable %Name% remains set within the current Command > Processor. When you modify this batch file like so: > @echo off > setlocal > set Name=ss > endlocal > > then the variable %Name% is lost the moment the batch file ends. In > either case the variable is lost when the current Command Processor is > closed. To prevent this, you can use setx.exe. I recommend you test > these concepts in order to become comfortable with them. ss.
Logon script help
Batch Script Text file parse Drive Mapping in Server 2008 Issues when launching a vbscript file from hta interface file Re: Updating AD with a script convert vb script to exe Command to add registry entry looking for a code to add data Total size of sql databases Scripting, Local Admin Account |
|||||||||||||||||||||||