Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define a DOSKEY alias for multiple commands?

Following on from an answer to this question

For the Windows command prompt I can define aliases as follows:

@echo off
DOSKEY ns=npm start
DOSKEY nsr=npm run serve

I want to define an alias that will combine these two commands. I tried the following:

@echo off
DOSKEY nss=npm start && npm run serve

When I try to open the command prompt the window will open but the > prompt does not appear.

I think that the inclusion of && is causing a problem.

like image 622
gburnett Avatar asked Nov 27 '17 09:11

gburnett


4 Answers

The command separator for DOSKEY is $T

For your example:

DOSKEY nss=npm start $T npm run serve
like image 151
AyrA Avatar answered Oct 27 '22 08:10

AyrA


I looked at an answer to a question on superuser. The following approach resolved my problem:

@echo off
DOSKEY nss=npm start ^&^& npm run serve
like image 27
gburnett Avatar answered Oct 27 '22 08:10

gburnett


My approach is to load the macros from a text file:

a.bat:
    @doskey /macrofile=C:\%HOMEPATH%\bin\aliases.txt

and in the macro file, && works:

aliases.txt:
    cl=cd /d $* && dir

Then if I type "cl bin" from HOMEPATH, it does "cd /d bin" and then "dir":

C:\Users\mike> cl bin
09/17/2020  09:27 AM             1,303 a.bat
09/30/2020  03:17 PM               886 aliases.txt
like image 30
mike scholtes Avatar answered Oct 27 '22 09:10

mike scholtes


Try writing it as a batch file and then calling the batch file use the DOSKEY command

REM do_npm.bat
npm start
npm run serve

Then, run the DOSKEY command

DOSKEY npm=do_npm.bat

See if that works for you

like image 2
Stanislaus Brown Avatar answered Oct 27 '22 09:10

Stanislaus Brown