I have a farily simple doskey macro

DOSKEY s="C:\Program Files (x86)\Git\bin\sh.exe" --login

So I could switch from command prompt to git shell by s

But sometimes I only want to execute a single command in shell and return to command line. For that I either have to enter shell, do stuff, exit. Or I could modify the doskey macro

DOSKEY s="C:\Program Files (x86)\Git\bin\sh.exe" --login -c "$*"

But that would mean I can't use it to do the former now, i.e enter shell, it's for executing only now.

I was wondering if I could have it conditionally choose between the two based on whether or not I have passed it another argument. So s would do the former, but s echo hello would do the latter.

Is there a way to do this?


You can use any standard CMD.EXE commands within your macro definition. The IF command can test if you have at least one paramater passed and branch accordingly.

doskey s=if $1. equ . ("C:\Program Files (x86)\Git\bin\sh.exe" --login) else "C:\Program Files (x86)\Git\bin\sh.exe" --login -c "$*"
  • 1
    Please add a short explanation of how this command works. – Nifle Jan 4 '15 at 20:57
  • 1
    $* will put everything entered after 's' on the command to be executed. – Alfergon Apr 4 '16 at 7:06

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.