How to create bash alias with argument? [duplicate]

Very simple;

alias lsps="ps -elf | grep"

Command line arguments will be added automatically to the end of the alias:

lsps arg1 arg2 arg3 => converted to => ps -elf | grep arg1 arg2 arg3

That works only when you want to add arguments to the end of alias.

If you want to get arguments of the alias inside of the expanded command line you must use functions:

For example:

lsps()
{
    ps -elf | grep "$1" | grep -v grep
}

Functions as well as aliases can be saved in your ~/.bashrc file )or a file that is included from it):

$ cat /tmp/.bash_aliases
lsps()
{
    ps -elf | grep "$1" | grep -v grep
}

$ . /tmp/.bash_aliases
$

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)