2

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?

  • @FrankThomas setx /? | findstr /r '\/M' does not work (it is the wrong kind of quotes) – DavidPostill Jul 23 at 16:05
1

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
         NT\CurrentVersion\CurrentBuildNumber" /M
         CurrentVersion\CurrentBuildNumber" /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
         NT\CurrentVersion\CurrentBuildNumber" /M
         CurrentVersion\CurrentBuildNumber" /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
         NT\CurrentVersion\CurrentBuildNumber" /M
         CurrentVersion\CurrentBuildNumber" /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
         NT\CurrentVersion\CurrentBuildNumber" /M
         CurrentVersion\CurrentBuildNumber" /M

F:\test>

Further Reading

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.