Wednesday, February 7, 2024

[SOLVED] Unix ksh alias parameter for multiple commands?

Issue

I did a 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?


Solution

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
}


Answered By - tripleee
Answer Checked By - Mildred Charles (WPSolving Admin)