2

I want to do: foo || pwd So as foo command fails I need just to get the second output pwd but I dont want the line No command 'foo' found, did you mean....

How can I do it? thanks

2 Answers 2

2

You need to redirect the STDERR output of foo to /dev/null so you don't see the errors.

foo 2>/dev/null || pwd
Sign up to request clarification or add additional context in comments.

2 Comments

Note that the error message can be redirected because it comes from the command_not_found_handle hook which runs in place of the missing command, rather than from the shell that spawns the command.
Pedantically, the error message can be redirected merely because it's printed on stderr. It doesn't really matter which process produces it.
1

You can redirect the standard error of the first command

foo 2> /dev/null || pwd

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.