开发者

Unix ksh alias parameter for multiple commands?

开发者 https://www.devze.com 2023-04-06 04:46 出处:网络
I did a 开发者_StackOverflow中文版research and found some solutions but none of them worked for me... Maybe could you help me ?

I did a 开发者_StackOverflow中文版research and found some solutions but none of them worked for me... Maybe could you help me ? I've 2 exec : prog1 and prog2. (ksh) I would like to run them, at the same time with the alias "e"

So I did this:

e TEST

It should be translated by

prog1 TEST

prog2 TEST

I tried :

ALIAS e='prog1 $1; prog2 $1'

OR

e() {

prog1 $1 | prog2 $1

}

Without success.

Do you have any solutions?


The function should work but you separate commands with a semicolon, not a pipe. Or just put them on separate lines - newline is a valid command separator, too.

e() {
    prog1 $1
    prog2 $1
}

You should properly have double quotes around $1, and in the general case, you should cope if there is more than one parameter; use "$@" to pass on the entire parameter list, or loop over the parameters:

e() {
    local a
    for a; do
        prog1 "$a"
        prog2 "$a"
    done
}


You say 'run them at the same time', then you need to run one (or both) in the background.

alias e='prog1 $1 &; prog2 $1 &;'

alias will not be recognized when capitalized.

Aliases do no accept arguments, use a function.

 function e { prog1 "$1" & ; prog2 "$1" & ; }

Tested with

function e { sleep "$1" & ; sleep "$1" & ; }

output

/home/shellter:>e 7
[1]     384512
[2]     267648
/home/shellter:>jobs
[2] +  Running                 e 7
[1] -  Running                 e 7
/home/shellter:>jobs
[2] +  Done                    e 7
[1] -  Done                    e 7

50% acceptance rate? You must be asking really difficult questions.

0

精彩评论

暂无评论...
验证码 换一张
取 消