1

I would like to run this command:

cmd -arg1 foo -arg2 bar

but, if cmd-better is available, I prefer to execute it with same arguments:

cmd-better -arg1 foo -arg2 bar

Finally, my question is, it is possible to have this in only one line, for example:

(cmd-better || cmd) -arg1 foo -arg2 bar

(which means execute cmd-better (if available) with those arguments, else execute cmd with same arguments.

1 Answer 1

2

You can do something like this:

"$(command -v cmd-better cmd | head -n 1)" -arg1 foo -arg2 bar

but I wouldn't recommend it.

I'd do it ahead of time and store the command you want in a variable

Something like:

if ! cmd=$(command -v cmd-better); then
    cmd=$(command -v cmd)
fi

"$cmd" -arg1 foo -arg2 bar
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.