DOSKEY username

Can I remember an alias with DOSKEY? A simple example. I want to do something like this:

DOSKEY a=someCommand
DOSKEY b=someOtherCommand
DOSKEY c=andAThirdCommand

:: How to do this? -> DOSKEY all=a+b+c

I already know that I can do this by writing this:

DOSKEY all=someCommand ^& someOtherCommand ^& andAThirdCommand

but in the sense of reusing the material, I would like to reuse my specific aliases on top. Is this possible as I wish?

Thank!

PS: I saw it here, but this is not a satisfactory answer. This doesn't seem to work. :(

+4
source share
1 answer

Good question, it's hard to answer ... However, I can offer a workaround with a simple script (s) package.

Suppose we defined macros doskey a=commandAand doskey a=commandBand doskey c=commandC.

  • : script, . dem ( de fine m acro) - path. dem acb a c b acb ( ) : doskey acb=commandA $T commandC $T commandB. , script script dsk (: , , ).

  • : script, . dsk ( d o sk ey) - path. dsk a b c a, b c . ( ), script, . script ,

    • % percent, doskey a=echo %variable% / for, doskey a=for /F "tokens=*" %G in ('dir /b /s *.txt') do @echo %G;
    • $T ( & ), doskey a=dir $T set; $T & ( , ).

/ ( , ); dsk script

  • a for %%parameter; vetoed : %%{ ( ) %%? %%@ ( )
  • , doskey a=dir ^> somefile;
  • ^& ( doskey intrinsic $T);
  • .bat .cmd ( call %xitem% %xitem% :doItem ( 50- );
  • , ...

script dsk :

:: dsk.bat
@ECHO OFF >NUL
@SETLOCAL enableextensions enabledelayedexpansion
set "CheckOnly=0"

set "DoneList="
set "ToDoList="
set "xitem=x"
for %%{ in (%*) do (
  set "_G_found=0"
  echo.
  for /F "tokens=1* delims==" %%? in ('doskey /macros') do (
    if /i "%%{"=="%%?" (
      for /F "tokens=*" %%_ in ("%%@") do set "item=%%_"
      if /i "!item:~0,3!"=="for" set "item=!item:%%=%%%%!"
      if "%CheckOnly%"=="1" (
          echo :  to do: '!item!'
      ) else (
          echo :  To Do: '!item!'
          call :doItem !item!
      )
      set "DoneList=!DoneList! +%%{"
      set "_G_found=1"
    ) 
  )
  if "!_G_found!"=="0" (
    set "DoneList=!DoneList! -%%{"
    echo :  macro: [%%{] ^(not found^)
    if "!ToDoList!"=="" set "ToDoList=!ToDoList!, [%%{]"
    if "!ToDoList!"=="!ToDoList:[%%{]=!" set "ToDoList=!ToDoList!, [%%{]"
  )
)
echo.
echo :  
echo :    trailing progress report
echo :  
if "%ToDoList%"=="" (
    echo :    all found: %DoneList:~1%
) else (
    echo :    +found, -not found: %DoneList:~1%
    echo :   %ToDoList:~2% not found in macro name list 
)
echo :    end of batch %~f0
echo :  
:endlocal
@ENDLOCAL
@goto :eof

:doItem
  set "xitem=%*"
  set "xitem=%xitem:$T=&%"
  %xitem%
@goto :eof

:

d:\bat>doskey /macros
y=for /F "tokens=*" %g in ('dir /b rand.bat') do @echo %g
x=dir /B /AD $T dir /B /AD "D:\Remote\bat\COCL\bu bu bu" $T set y
a=echo CheckOnly=%CheckOnly%
b=rand.bat

dsk y b a x n :

d:\bat>dsk y b a x n

:  To Do: 'for /F "tokens=*" %%g in ('dir /b rand.bat') do @echo %%g'
rand.bat

:  To Do: 'rand.bat'
The system cannot find the batch label specified - doItem

:  To Do: 'echo CheckOnly=%CheckOnly%'
CheckOnly=0

:  To Do: 'dir /B /AD $T dir /B /AD "D:\Remote\bat\COCL\bu bu bu" $T set y'
files
a.dot 1.dot 2.dot 3
Environment variable y not defined

:  macro: [n] (not found)

:
:    trailing progress report
:
:    +found, -not found: +y +b +a +x -n
:   [n] not found in macro name list
:    end of batch d:\bat\dsk.bat
:
d:\bat>

script ( CheckOnly, 1= , 0= ).

+3

All Articles