How can I create an alias that passes additional arguments?

I have an executable that I use often:

/dir1/dir2/dir3/dir4/executable argv[1] argv[2] argv[3]

I know that I can set an alias for the executable:

alias myexecutable = '/dir1/dir2/dir3/dir4/executable'

and then call it

myexecutable argv[1] argv[2] argv[3]

However, I’d like to call it like this

myexecutable argv[1]

because the first argument is the only one that ever changes. The second and third one should always be passed as the same every time.

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

Aliases don’t handle arguments. Define a function:

myfunc () {
    /dir1/dir2/dir3/dir4/executable "$1" fixed-argv2 fixed-argv3
}

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply