Table of Contents

Bash - Alias (of a command) - Builtin command

About

Alias allows to define shortcuts and synonyms for commonly used:

They allow a string to be substituted for a word when it is used as the first word of a simple command.

The shell maintains a list of aliases that may be:

Example

For instance, the Syntax is

alias AliasName='command -arguments'
alias AliasName='FullPathScript -arguments'

Syntax

The basic syntax is:

alias [-p] [name[=value] ...]

where:

And:

Return value:

Note aliases are not expanded by default in non-interactive shell, and it can be enabled by setting the expand_aliases shell option using shopt.

Configuration

Expansion

To use alias in script:

shopt -s expand_aliases

Expansion

Rules

Alias Expansion Process

Aliases in function

Management

Made the aliases permanent

Aliases can be put in the startup script in order to become permanent.

Extended Example from the OBIEE VM.

#alias created 
alias startWLS='/bishiphome/Middleware/user_projects/domains/bifoundation_domain/bin/startWebLogic.sh'
alias stopWLS='/bishiphome/Middleware/user_projects/domains/bifoundation_domain/bin/stopWebLogic.sh'

alias startOPMN='/bishiphome/Middleware/instances/instance1/bin/opmnctl startall'
alias stopOPMN='/bishiphome/Middleware/instances/instance1/bin/opmnctl stopall'
alias statusOPMN='/bishiphome/Middleware/instances/instance1/bin/opmnctl status -l'

alias stopOBIPS='${FMW_HOME}/instances/instance1/bin/opmnctl stopproc ias-component=coreapplication_obips1'
alias startOBIPS='${FMW_HOME}/instances/instance1/bin/opmnctl startproc ias-component=coreapplication_obips1'
alias restartOBIPS='stopOBIPS && startOBIPS'

alias startESSB='/epm/Middleware/user_projects/epmsystem1/bin/startEssbase.sh'
alias stopESSB='/epm/Middleware/user_projects/epmsystem1/bin/stopEssbase.sh'
alias startAPS='/epm/Middleware/user_projects/epmsystem1/bin/startAnalyticProviderServices.sh'
alias stopAPS='/epm/Middleware/user_projects/epmsystem1/bin/stopAnalyticProviderServices.sh'

alias startOIDopmn='/idm/Middleware/asinst_1/bin/opmnctl start'
alias startOID='/idm/Middleware/asinst_1/bin/opmnctl startproc ias-component=oid1'
alias stopOID='/idm/Middleware/asinst_1/bin/opmnctl stopall'
alias statusOID='/idm/Middleware/asinst_1/bin/opmnctl status -l'

Lists the current aliases

alias
alias cp='cp -i'
alias l.='ls -d .* --color=tty'
alias ll='ls -l --color=tty'
alias ls='ls --color=tty'
alias mv='mv -i'
alias rm='rm -i'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'

Remove an alias

unalias myALiasName

Shortcut the frequently used command

Example:

alias startOPMN ='/bishiphome/Middleware/instances/instance1/bin/opmnctl startall'
alias editHttpd="gedit /etc/httpd/conf/httpd.conf"

Specify the default parameters

If you want ls to show colors by default with the ls command:

alias ls='ls --color=yes'

Call an Alias with parameters

Alias doesn't support parameter whereas a function does.

Having a function in your startup script will permit to call them like alias.

For instance, to use ssh to copy files to a location on a server you can use this function

sendpic() { scp $* [email protected]:/www/misc/Pictures/; }

Standardize the name of commands across multiple operating systems

For people accustomed to MS-DOS commands, the following aliases can be defined so that a Unix-like operating system appears to behave more like MS-DOS:

alias dir="ls"
alias copy="cp"
alias rename="mv"
alias md="mkdir"
alias rd="rmdir"
alias del="rm -i"

Documentation / Reference