alias

Syntax

alias <ALIAS-NAME> <COMMAND-STRING>[; <command-string>]...

no alias <ALIAS-NAME>

Description

Defines an alias for a CLI command. The alias and its definition are valid only for the user that creates the alias.

Use the no form of this command to remove a defined alias from the configuration.

Command context

config

Parameters

<ALIAS-NAME>

Specifies the name of the alias you are defining.

<COMMAND-STRING>

Specifies a command—including parameters—that defines the alias. The alias definition can include multiple commands. Separate multiple commands with semicolons (;). Maximum length: 400 characters.

For commands that require user-supplied parameters, use $1 through $n, in order, as placeholders. These parameters are replaced by the corresponding arguments from the command line, and should correspond to the number of parameters available in the original command. For alias definitions that include multiple commands, continue numbering through the entire alias. Do not restart numbering for each <command-string>.

Authority

Administrators

Example alias defined by a single command

The following example creates the alias hst for the hostname command.

The hostname command has a single argument, therefore $1 is needed to support it.

switch(config)# alias hst hostname $1

The show alias command shows the aliases that are defined on the switch.

switch(config)# do show alias
 Alias Name      Alias Definition
 ------------------------------------------------------------------------
 hst             hostname $1

For subsequent commands, you and other users can enter hst instead of hostname. For example:

switch(config)# hst myhost
myhost(config)#

Example alias defined by multiple commands

Suppose you want to configure an alias for the following commands, but you want to be able to specify the interface ID, IP address, and MTU value for each command you execute:

interface 1/1/1; no shutdown; ip address 10.0.0.1/24; lldp receive; mtu 1200

You can define an alias—intf_config in this example—to execute the commands:

alias intf_config interface $1; no shutdown; ip address $2; lldp receive; mtu $3; exit

The show alias command shows the aliases that are defined on the switch. Use the do command to execute the show command from the config context.

switch(config)# do show alias
 Alias Name      Alias Definition
 -------------------------------------------------------------------------------
 int_config      interface $1; no shutdown; ip address $2; lldp receive; mtu $3; exit

After the alias is defined, you can execute the intf_config alias with the values you want to use. For example:

switch(config)# intf_config 1/1/1 10.0.0.1/24 1200
...
switch(config)# intf_config 1/1/2 20.0.0.1/24 1500
...
switch(config)# intf_config 1/1/3 30.0.0.1/24 1600
...