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 (~!#$*();`'"<>?\).
1
exec 3<&1
2
echo 123 > somefile
3
echo 456 >> somefile
4
echo abc > "$file"
5
echo def >> "$file"
6
kill -1 "$pid" > /dev/null 2>&1
Copied!
Here document redirections should appear at the end of the line.
1
cat >> file <<EOF
2
Added to file
3
EOF
4
if some condition; then
5
cat >> file <<-EOF
6
Added to file
7
EOF
8
fi
Copied!
Copy link