Redirection

Redirection to a file should have a single space after the operator before the file. If the file contains a variable, it should be quoted. File descriptor alterations should have no whitespace. All redirections should occur at the end of the line. Do not quote static paths unless they contain special characters (~!#$*();`'"<>?\).

exec 3<&1
echo 123 > somefile
echo 456 >> somefile
echo abc > "$file"
echo def >> "$file"
kill -1 "$pid" > /dev/null 2>&1

Here document redirections should appear at the end of the line.

cat >> file <<EOF
Added to file
EOF
if some condition; then
    cat >> file <<-EOF
    Added to file
    EOF
fi

Last updated