Bash - Alias (of a command) - Builtin command

Bash Liste Des Attaques Ovh

Bash - Alias (of a command) - Builtin command

About

Alias allows to define shortcuts and synonyms for commonly used:

Syntax

The basic syntax is:

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

where:

  • p is to only print the aliases
  • [name[=value] …] are arguments. When they are supplied, an alias is defined for each name whose value is given.

And:

  • value: A trailing space in value causes the next word to be checked for alias substitution when the alias is expanded.
  • name: For each name in the argument list for which no value is supplied, the name and value of the alias is printed.

Return value:

  • Alias returns true unless a name is given for which no alias has been defined.

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

Example

For instance, the Syntax is

  • for a command:
alias AliasName='command -arguments'
  • for a script
alias AliasName='FullPathScript -arguments'

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:

  • To start services such as OPMN
alias startOPMN ='/bishiphome/Middleware/instances/instance1/bin/opmnctl startall'
  • To edit a configuration file
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





Discover More
Bash Liste Des Attaques Ovh
Bash - (Environment) Variable

A variable is a parameters referenced by a name. parameter A variable has: a value and zero or more attributes (such as integer, ...). Attributes are assigned using the declare builtin command....
Bash Liste Des Attaques Ovh
Bash - Builtin Commands

builtin refers to: a builtin command. See or to the specific builtin command. See (useful when defining a function whose name is the same as a shell builtin) The builtin command execute the specified...
Bash Liste Des Attaques Ovh
Linux - ls (List directory content)

ls is a Linux Command utility that lists the contents of a directory ll is an alias of “ls -la” You can also list files and directories with the find command This script will: list the...
Tmux (terminal multiplexer)

Tmux stands for terminal multiplexer. It will let you: switch between several programs in one terminal, detach them, while they are running in the background, and reattach them to a different...
Bash Liste Des Attaques Ovh
What is a Command in Bash?

This page is command in bash. Command are in bash the expression unit A command (or an expression) is a sequence of words separated by blanks, terminated by a control operator. Each command execution...



Share this page:
Follow us:
Task Runner