Hide error message in bash
Is the error message coming from the head
program (like, file not found)?
In this case you have to redirect the output from inside parens:
firs_line=$(head -n 1 file 2>/dev/null)
Moreover, you only have to redirect standard error (and not standard output which is supposed to be catched by $()
to be stored in firs_line
firs_line="$([ -r file ] && head -n 1 file)"