How to make an alias for a function in batch?

974 Views Asked by At

I want to create an alias for a function in batch something like this:

echo off 
DOSKEY getMessage=call :message

:message
  SET answer=
  SET /P answer=What is your message? :
  IF EXIST %answer% (
  echo %answer%
) else(
 goto mesage
)

I don't have experience with batch but I want to make an alias with some commands for git.

2

There are 2 best solutions below

0
On

Here are some methods to create Simple and Complex aliases:

  • $G or $g - Redirects output. Use either of these special characters to send output to a device or a file instead of to the screen. This character is equivalent to the redirection symbol for output (>).
  • $G$G or $g$g - Appends output to the end of a file. Use either of these double characters to append output to an existing file instead of replacing the data in the file. These double characters are equivalent to the append redirection symbol for output (>>).
  • $L or $l - Redirects input. Use either of these special characters to read input from a device or a file instead of from the keyboard. This character is equivalent to the redirection symbol for input (<). $B or $b - Sends macro output to a command. These special characters are equivalent to using the pipe (**
  • $T or $t - Separates commands. Use either of these special characters to separate commands when you create macros or type commands on the doskey command line. These special characters are equivalent to using the ampersand (&) on a command line.
  • $$ - Specifies the dollar-sign character ($).
  • $1 through $9 - Represent any command-line information you want to specify when you run the macro. The special characters $1 through $9 are batch parameters that enable you to use different data on the command line each time you run the macro. The $1 character in a doskey command is similar to the %1 character in a batch program.
  • $* - Represents all the command-line information that you want to specify when you type the macro name. The special character $* is a replaceable parameter that is similar to the batch parameters $1 through $9, with one important difference: everything you type on the command line after the macro name is substituted for the $* in the macro.

An example of creating an alias that takes an url from the user and pings it:

doskey getping="set /p URL=Enter an URL:$Tping %URL%"
0
On

I found out how to do it, for someone who is interesting in this here is how I did:

DOSKEY getMessage=here is a path to another .cmd file where is your script