For bash script, I can use "$@" to access arguments. What's the equivalent when I use an alias?
|
|
|
Aliases are like commands in that all arguments to them are passed as arguments to the program they alias. For instance, if you were to alias If you want to have actual control over how the arguments are interpreted, then you could write a function like so:
|
|||||||
|
|
You don't have to do anything, actually; aliases do this automatically. For instance:
You will see foo.txt's first page, and |
|||
|
|
|
Adding to the present answers, an important thing to realize about how aliases work is that all the parameters you type after an aliased command will be used literally at the end. So there is no way to use alias for two commands (piped or not), out of which the first should interpret the parameters. To make it clear, here's an example of something that would not work as expected:
(an example inspired by this question) this will always use the output of lsswp /tmp/ would be equivalent to For all purposes where the arguments should be used somewhere in the middle, one needs to use a |
|||
|
|