简体   繁体   中英

linux alias to simplify a command line

I am new to writing Linux scripts (in fact I'm not sure if the proper term is Linux script or baSH script). I do understand source -ing and the alias feature such as this:

alias l='ls -ltra'

What I want to accomplish is type the following shortcut statement

php ~/path/to/longProgram.php Argument1 -x -y -z --long-switch long-switch-value

as this:

lp Argument1 -x -y -z --long-switch long-switch-value

ie where I can call lp from any where, and where all of the arguments as-given get passed to longProgram.php . How would I do this as an alias?

To make an invocation of lp Argument1 -x -y -z --long-switch long-switch-value result in a call to php ~/path/to/longProgram.php Argument1 -x -y -z --long-switch long-switch-value , you have a few options. The simplest is to put this in your ~/.bashrc:

lp() { php "$HOME/path/to/longProgram.php" "$@"; }
alias lp='php ~/path/to/longProgram.php'

would normally work, even if it is not a good practice. An alias is simply a find and replace feature so I see no reason of this not working. However you need to be the exact user whose home contain the program.

PS: Also verify that lp is not already assigned to another command.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM