I want to create an alias that can still take input, like:

alias ytx='youtube-dl -ciw -f bestaudio --yes-playlist

Is this possible within windows?

I tried bash aliases equivalent for powershell? but it doesn't allow for input at the end.


The simplest approach, which works in any Windows version, is using common batch files, stored in a common folder available in your PATH.

For passing input to batch files, use %*, which evaluates to "all parameters passed to the batch file command line", or, use %1, %2, ... %9 to refer to individual parameters.

Personally, I keep my batch files in C:\Batch and place it in the begining of my PATH. When running the batch files, you could omit the .bat suffix, to get a similar look-and-feel to bash aliases.

Few examples of my own:

  • s3cmd.bat, which contains: python c:\devtools\s3cmd-2.0.0\s3cmd %*. All parameters are passed directly to the actual s3cmd program.
  • clangcheck.bat, which is a shorthand for: clang-check -analyze -extra-arg -Xclang -extra-arg -analyzer-output=text %*. Here, the batch parameters are passed along with extra arguments to clang-check.
  • epoch_to_time.bat, which converts Unix epoch time to readable local time.
    It contains: perl -pe "s/([\d]{10})/localtime $1/eg;" %1. Here, %1 is the epoch time to convert, which is expected as a single parameter.
| improve this answer | |

The equivalent command is the doskey command, which you may use as:

doskey ytx=youtube-dl -ciw -f bestaudio --yes-playlist $*

where $* represents all the parameters.

Here is a small example that echos its parameters:

enter image description here

Doskey can also be used in PowerShell. For more information see this answer.

For making a doskey macro persistent across sessions, see the post Create permanent DOSKEY in Windows cmd.

| 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.