I would use cat
together with here-doc syntax for this:
cat <<EOF > /etc/nsswitch.conf
group: compat
shadow: compat
hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4
...
EOF
The statement above will overwrite or create the file with the contents between the first line and EOF
. In the form above even variables like group: $group
would be expanded by bash. If you don't want this, then use <<'EOF'
(note the single quotes '
around the EOF
)