AnswerBun.com

How to separate command switches (/x) from arguments in windows?

Super User Asked by Herdsman on October 3, 2020

I know in linux, I can just write command -a -b - "arg1" "arg2"..., where single hyphen is "option/switch" separator. But how can I do similar in windows cmd?

I would like to see only particular option/switch from help:
c:> setx /? | findstr /r '/m', where the /m switch I want to find. but the findstr uses it as another switch:

FINDSTR: Bad command line.

How to achieve that?

One Answer

I want to find the /m switch

I'm using:

setx /? | findstr /r '/m'
  1. You do not need the /r switch (which specifies a regular expression) as '/m' is not a regular expression.

  2. You are using the wrong kind of quotes (single ' instead of "), it should be "/m"

  3. setx /? outputs /M so you either need to use /I (ignore case) or "/M"

  4. The / in "/m" needs to be escaped (using ), ie "/m", if you are not using the /C: (Use string as a literal search string) option

The following commands all do what you want:

setx /? | findstr "/M"
setx /? | findstr /c:"/M"
setx /? | findstr /i "/m"
setx /? | findstr /i /c:"/m"

Example output:

F:test>setx /? | findstr "/M"
    SETX [/S system [/U [domain]user [/P [password]]]] var value [/M]
    SETX [/S system [/U [domain]user [/P [password]]]] var /K regpath [/M]
         /F file {var {/A x,y | /R x,y string}[/M] | /X} [/D delimiters]
    /M                     Specifies that the variable should be set in
    SETX MACHINE "COMPAQ COMPUTER" /M
         NTCurrentVersionCurrentBuildNumber" /M
         CurrentVersionCurrentBuildNumber" /M

F:test>setx /? | findstr /c:"/M"
    SETX [/S system [/U [domain]user [/P [password]]]] var value [/M]
    SETX [/S system [/U [domain]user [/P [password]]]] var /K regpath [/M]
         /F file {var {/A x,y | /R x,y string}[/M] | /X} [/D delimiters]
    /M                     Specifies that the variable should be set in
    SETX MACHINE "COMPAQ COMPUTER" /M
         NTCurrentVersionCurrentBuildNumber" /M
         CurrentVersionCurrentBuildNumber" /M

F:test>setx /? | findstr /i "/m"
    SETX [/S system [/U [domain]user [/P [password]]]] var value [/M]
    SETX [/S system [/U [domain]user [/P [password]]]] var /K regpath [/M]
         /F file {var {/A x,y | /R x,y string}[/M] | /X} [/D delimiters]
    /M                     Specifies that the variable should be set in
    SETX MACHINE "COMPAQ COMPUTER" /M
         NTCurrentVersionCurrentBuildNumber" /M
         CurrentVersionCurrentBuildNumber" /M

F:test>setx /? | findstr /i /c:"/m"
    SETX [/S system [/U [domain]user [/P [password]]]] var value [/M]
    SETX [/S system [/U [domain]user [/P [password]]]] var /K regpath [/M]
         /F file {var {/A x,y | /R x,y string}[/M] | /X} [/D delimiters]
    /M                     Specifies that the variable should be set in
    SETX MACHINE "COMPAQ COMPUTER" /M
         NTCurrentVersionCurrentBuildNumber" /M
         CurrentVersionCurrentBuildNumber" /M

F:test>

Further Reading

Correct answer by DavidPostill on October 3, 2020

Add your own answers!

Related Questions

Problems with the WD passport

1  Asked on January 18, 2021 by w0051977

       

Concatenating an image with a video with ffmpeg

1  Asked on January 18, 2021 by lance

 

bootable USB not booting

1  Asked on January 17, 2021 by max-neumann

     

Virtualbox NAT and host-only connection

3  Asked on January 17, 2021 by beach-chicken

   

Generate Time ranges in Excel 365

1  Asked on January 17, 2021 by spydercoll

 

Opening port: basic questions

2  Asked on January 16, 2021 by starbuck

       

config Nginx to start server in two LANs

0  Asked on January 16, 2021 by zhaogang

 

How can I count unique values in Excel?

1  Asked on January 14, 2021 by berg_durden

   

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP