How can I automatically specify or group command line arguments for an alias in bash?

I have a script that takes a command and executes it on a remote host. It works great, for example:

$ rexec "ant build_all"

will execute the command "ant build_all" on the remote system (passing it through SSH, etc.).

Since I'm lazy, I want to set up an alias for this command (and ultimately a few others), for example, that I can just call

$ rant build_all

and bash whether it will automatically call

$ rexec "ant build_all"

I tried to do this with an alias, but if I define

alias rant=rexec ant

then any arguments passed to "rant" will simply be added to the end, for example:

$ rant build_all -Dtarget=Win32
(interpreted as:)
$ rexec "ant" build_all -Dtarget=Win32

This fails because rexec really only accepts one argument and ignores the others.

, bash wrapper script, , bash - , , - perl- (, qw//) .

+3
3

.

function rant () {
    rexec "ant $*"
}

, .

+3

G, : rex , :

function rex {
    run_remote.sh -c "$*"
}

rexec , :

alias rant="rex ant"

, .

, bash. , , script.

, !

edit: "rexec" "rex", , "rexec"

+2

You can do this as a function, rather than an alias:

function rant { rexec "ant $1"; }

You can call it on the command line as an alias

0
source

Source: https://habr.com/ru/post/1699564/


All Articles