I want to read a file into a variable. I can do this with a stdin redirection operator:
MYVAR=$(</some/file)
However, the file is a sysfs node and may error out. I'm also using set -o errtrace
and want to ignore the error if it happens, just getting an empty variable. I've tried the following but surprisingly it always gives an empty variable.
MYVAR=$(</some/file || true)
Why is it always empty?
I could use cat
:
MYVAR=$(cat /some/file 2>/dev/null || true)
but would like to know if it's possible without.