Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

Prevent error if file does not exist

I need to get the contents of a file but want to prevent an error if it does not exist.

Is it possible to do something like this?
cat my-file.txt || false
by

1 Answer

Kajalsi45d
Close stderr with 2>&-:
cat my-file.txt 2>&- || false

Login / Signup to Answer the Question.