Why is this echo command not working?

I want to overwrite /etc/postfix/master.cf with my own content. I'm using echo "<content>" > /etc/postfix/master.cf to try and accomplish this.

But when I do:

echo "#
# Postfix master process configuration file. For details on the format
# of the file, see the master(5) manual page (command: 'man 5 master').
#
# Do not forget to execute 'postfix reload' after editing this file.
#
# ==========================================================================
# service type private unpriv chroot wakeup maxproc command + args
# (yes) (yes) (yes) (never) (100)
# ==========================================================================
smtp inet n - - - - smtpd
#smtp inet n - - - 1 postscreen
#smtpd pass - - - - - smtpd
#dnsblog unix - - - - 0 dnsblog
#tlsproxy unix - - - - 0 tlsproxy
submission inet n - - - - smtpd -o content_filter=spamassassin -o syslog_name=postfix/submission -o smtpd_tls_security_level=encrypt -o smtpd_sasl_auth_enable=yes -o smtpd_client_restrictions=permit_sasl_authenticated,reject
# -o milter_macro_daemon_name=ORIGINATING
#smtps inet n - - - - smtpd
# -o syslog_name=postfix/smtps
# -o smtpd_tls_wrappermode=yes
# -o smtpd_sasl_auth_enable=yes
# -o smtpd_client_restrictions=permit_sasl_authenticated,reject
# -o milter_macro_daemon_name=ORIGINATING
#628 inet n - - - - qmqpd
pickup fifo n - - 60 1 pickup
cleanup unix n - - - 0 cleanup
qmgr fifo n - n 300 1 qmgr
#qmgr fifo n - n 300 1 oqmgr
tlsmgr unix - - - 1000? 1 tlsmgr
rewrite unix - - - - - trivial-rewrite
bounce unix - - - - 0 bounce
defer unix - - - - 0 bounce
trace unix - - - - 0 bounce
verify unix - - - - 1 verify
flush unix n - - 1000? 0 flush
proxymap unix - - n - - proxymap
proxywrite unix - - n - 1 proxymap
smtp unix - - - - - smtp
relay unix - - - - - smtp
# -o smtp_helo_timeout=5 -o smtp_connect_timeout=5
showq unix n - - - - showq
error unix - - - - - error
retry unix - - - - - error
discard unix - - - - - discard
local unix - n n - - local
virtual unix - n n - - virtual
lmtp unix - - - - - lmtp
anvil unix - - - - 1 anvil
scache unix - - - - 1 scache
#
# ====================================================================
# Interfaces to non-Postfix software. Be sure to examine the manual
# pages of the non-Postfix software to find out what options it wants.
#
# Many of the following services use the Postfix pipe(8) delivery
# agent. See the pipe(8) man page for information about ${recipient}
# and other message envelope options.
# ====================================================================
#
# maildrop. See the Postfix MAILDROP_README file for details.
# Also specify in main.cf: maildrop_destination_recipient_limit=1
#
maildrop unix - n n - - pipe flags=DRhu user=vmail argv=/usr/bin/maildrop -d ${recipient}
#
# ====================================================================
#
# Recent Cyrus versions can use the existing 'lmtp' master.cf entry.
#
# Specify in cyrus.conf:
# lmtp cmd='lmtpd -a' listen='localhost:lmtp' proto=tcp4
#
# Specify in main.cf one or more of the following:
# mailbox_transport = lmtp:inet:localhost
# virtual_transport = lmtp:inet:localhost
#
# ====================================================================
#
# Cyrus 2.1.5 (Amos Gouaux)
# Also specify in main.cf: cyrus_destination_recipient_limit=1
#
#cyrus unix - n n - - pipe
# user=cyrus argv=/cyrus/bin/deliver -e -r ${sender} -m ${extension} ${user}
#
# ====================================================================
# Old example of delivery via Cyrus.
#
#old-cyrus unix - n n - - pipe
# flags=R user=cyrus argv=/cyrus/bin/deliver -e -m ${extension} ${user}
#
# ====================================================================
#
# See the Postfix UUCP_README file for configuration details.
#
uucp unix - n n - - pipe flags=Fqhu user=uucp argv=uux -r -n -z -a$sender - $nexthop!rmail ($recipient)
#
# Other external delivery methods.
#
ifmail unix - n n - - pipe flags=F user=ftn argv=/usr/lib/ifmail/ifmail -r $nexthop ($recipient)
bsmtp unix - n n - - pipe flags=Fq. user=bsmtp argv=/usr/lib/bsmtp/bsmtp -t$nexthop -f$sender $recipient
scalemail-backend unix - n n - 2 pipe flags=R user=scalemail argv=/usr/lib/scalemail/bin/scalemail-store ${nexthop} ${user} ${extension}
mailman unix - n n - - pipe flags=FR user=list argv=/usr/lib/mailman/bin/postfix-to-mailman.py ${nexthop} ${user}
# SpamAssasin
spamassassin unix - n n - - pipe user=spamd argv=/usr/bin/spamc -f -e /usr/sbin/sendmail -oi -f ${sender} ${recipient}" > /etc/postfix/master.cf

I get a lot of errors:

echo "#
> # Postfix master process configuration file. For details on the format
> # of the file, see the master(5) manual page (command: 'man 5 master').
> #
> # Do not forget to execute 'postfix reload' after editing this file.
> #
> # ==========================================================================
> # service type private unpriv chroot wakeup maxproc command + args
> # (yes) (yes) (yes) (never) (100)
> # ==========================================================================
> smtp inet n - - - - smtpd
> #smtp inet n - - - 1 postscreen
> #smtpd pass - - - - - smtpd configuration details.
> configuration details.
#
> #
uucp unix - n n - - pipe
> uucp unix - n n - - pipe flags=Fqhu user=uucp argv=uux -r -n -z -a$sender - $nexthop!rmail ($recipient)
> flags=Fqhu user=uucp argv=uux -r -n -z -a$sender - $nexthop!rmail ($recipient)
#
-bash: !rmail: event not found
> #
# Other external delivery methods.
> # Other external delivery methods.
#
> #
ifmail unix - n n - - pipe
> ifmail unix - n n - - pipe flags=F user=ftn argv=/usr/lib/ifmail/ifmail -r $nexthop (> flags=F user=ftn argv=/usr/lib/ifmail/ifmail -r $nexthop (=yes
ipient)
> pient)
bsmtp unix - n n - - pipe
> bsmtp unix - n n - - pipe flags=Fq. user=bsmtp argv=/usr/lib/bsmtp/bsmtp -t$nexthop -f$sender $recipient
> flags=Fq. user=bsmtp argv=/usr/lib/bsmtp/bsmtp -t$nexthop -f$sender $recipient
scalemail-backend unix - n n - 2 pipe
> scalemail-backend unix - n n - 2 pipe flags=R user=scalemail argv=/usr/lib/scalemail/bin/scalemail-store ${nexthop} ${user} ${extension}
> flags=R user=scalemail argv=/usr/lib/scalemail/bin/scalemail-store ${nexthop} ${user} ${extension}
mailman unix - n n - - pipe
> mailman unix - n n - - pipe flags=FR user=list argv=/usr/lib/mailman/bin/postfix-to-mailman.py
> flags=FR user=list argv=/usr/lib/mailman/bin/postfix-to-mailman.py ${nexthop} ${user}
> ${nexthop} ${user}
# SpamAssasin
> # SpamAssasin
spamassassin unix - n n - - pipe
> spamassassin unix - n n - - pipe user=spamd argv=/usr/bin/spamc -f -e
> user=spamd argv=/usr/bin/spamc -f -e /usr/sbin/sendmail -oi -f ${sender} ${recipient}" > /etc/postfix/master.cf> /usr/sbin/sendmail -oi -f ${sender} ${recipient}" > /etc/postfix/master.cf 1 oqmgr
root@<redacted>-1:~# tlsmgr unix - - - 1000? 1 tlsmgr
tlsmgr: command not found
root@<redacted>-1:~# rewrite unix - - - - - trivial-rewrite
No command 'rewrite' found, did you mean: Command 'rewriter' from package 'ladr4-apps' (universe)
rewrite: command not found
root@<redacted>-1:~# bounce unix - - - - 0 bounce
No command 'bounce' found, did you mean: Command 'kbounce' from package 'kbounce' (main) Command 'bounced' from package 'sympa' (universe) Command 'bouncy' from package 'bouncy' (universe)
bounce: command not found
root@<redacted>-1:~# defer unix - - - - 0 bounce
No command 'defer' found, did you mean: Command 'refer' from package 'groff' (main)
defer: command not found
root@<redacted>-1:~# trace unix - - - - 0 bounce
No command 'trace' found, did you mean: Command 'btrace' from package 'blktrace' (universe) Command 'itrace' from package 'irpas' (multiverse) Command 'ltrace' from package 'ltrace' (main) Command 'mtrace' from package 'libc-dev-bin' (main) Command 'tracer' from package 'pvm-dev' (universe) Command 'grace' from package 'grace' (universe) Command 'xtrace' from package 'xtrace' (universe) Command 'tracd' from package 'trac' (universe) Command 'strace' from package 'strace' (main) Command 'dtrace' from package 'systemtap-sdt-dev' (universe) Command 'rtrace' from package 'radiance' (universe)
trace: command not found
root@<redacted>-1:~# verify unix - - - - 1 verify
The program 'verify' is currently not installed. You can install it by typing:
apt-get install argyll
root@<redacted>-1:~# flush unix n - - 1000? 0 flush
The program 'flush' is currently not installed. You can install it by typing:
apt-get install flush
root@<redacted>-1:~# proxymap unix - - n - - proxymap
proxymap: command not found
root@<redacted>-1:~# proxywrite unix - - n - 1 proxymap
proxywrite: command not found
root@<redacted>-1:~# smtp unix - - - - - smtp
The program 'smtp' is currently not installed. You can install it by typing:
apt-get install apcupsd
root@<redacted>-1:~# relay unix - - - - - smtp
No command 'relay' found, did you mean: Command 'rplay' from package 'rplay-client' (universe)
relay: command not found
root@<redacted>-1:~# # -o smtp_helo_timeout=5 -o smtp_connect_timeout=5
root@<redacted>-1:~# showq unix n - - - - showq
The program 'showq' is currently not installed. You can install it by typing:
apt-get install showq
root@<redacted>-1:~# error unix - - - - - error
No command 'error' found, did you mean: Command 'perror' from package 'mysql-server-5.5' (main)
error: command not found
root@<redacted>-1:~# retry unix - - - - - error
No command 'retry' found, did you mean: Command 'retrv' from package 'atfs' (universe)
retry: command not found
root@<redacted>-1:~# discard unix - - - - - discard
discard: command not found
root@<redacted>-1:~# local unix - n n - - local
-bash: local: can only be used in a function
root@<redacted>-1:~# virtual unix - n n - - virtual
No command 'virtual' found, did you mean: Command 'virtaal' from package 'virtaal' (universe)
virtual: command not found
root@<redacted>-1:~# lmtp unix - - - - - lmtp
No command 'lmtp' found, did you mean: Command 'lftp' from package 'lftp' (main) Command 'smtp' from package 'apcupsd' (universe) Command 'gmtp' from package 'gmtp' (universe) Command 'ldtp' from package 'ldtp' (universe) Command 'mtp' from package 'ferret-vis' (universe)
lmtp: command not found
root@<redacted>-1:~# anvil unix - - - - 1 anvil
anvil: command not found
root@<redacted>-1:~# scache unix - - - - 1 scache
No command 'scache' found, did you mean: Command 'ccache' from package 'ccache' (main)
scache: command not found
root@<redacted>-1:~# #
root@<redacted>-1:~# # ====================================================================
root@<redacted>-1:~# # Interfaces to non-Postfix software. Be sure to examine the manual
root@<redacted>-1:~# # pages of the non-Postfix software to find out what options it wants.
root@<redacted>-1:~# #
root@<redacted>-1:~# # Many of the following services use the Postfix pipe(8) delivery
root@<redacted>-1:~# # agent. See the pipe(8) man page for information about ${recipient}
root@<redacted>-1:~# # and other message envelope options.
root@<redacted>-1:~# # ====================================================================
root@<redacted>-1:~# #
root@<redacted>-1:~# # maildrop. See the Postfix MAILDROP_README file for details.
root@<redacted>-1:~# # Also specify in main.cf: maildrop_destination_recipient_limit=1
root@<redacted>-1:~# #
root@<redacted>-1:~# maildrop unix - n n - - pipe
The program 'maildrop' can be found in the following packages: * courier-maildrop * maildrop
Try: apt-get install <selected package>
root@<redacted>-1:~# flags=DRhu user=vmail argv=/usr/bin/maildrop -d ${recipient}
-d: command not found
root@<redacted>-1:~# #
root@<redacted>-1:~# # ====================================================================
root@<redacted>-1:~# #
root@<redacted>-1:~# # Recent Cyrus versions can use the existing 'lmtp' master.cf entry.
root@<redacted>-1:~# #
root@<redacted>-1:~# # Specify in cyrus.conf:
root@<redacted>-1:~# # lmtp cmd='lmtpd -a' listen='localhost:lmtp' proto=tcp4
root@<redacted>-1:~# #
root@<redacted>-1:~# # Specify in main.cf one or more of the following:
root@<redacted>-1:~# # mailbox_transport = lmtp:inet:localhost
root@<redacted>-1:~# # virtual_transport = lmtp:inet:localhost
root@<redacted>-1:~# #
root@<redacted>-1:~# # ====================================================================
root@<redacted>-1:~# #
root@<redacted>-1:~# # Cyrus 2.1.5 (Amos Gouaux)
root@<redacted>-1:~# # Also specify in main.cf: cyrus_destination_recipient_limit=1
root@<redacted>-1:~# #
root@<redacted>-1:~# #cyrus unix - n n - - pipe
root@<redacted>-1:~# # user=cyrus argv=/cyrus/bin/deliver -e -r ${sender} -m ${extension} ${user}
root@<redacted>-1:~# #
root@<redacted>-1:~# # ====================================================================
root@<redacted>-1:~# # Old example of delivery via Cyrus.
root@<redacted>-1:~# #
root@<redacted>-1:~# #old-cyrus unix - n n - - pipe
root@<redacted>-1:~# # flags=R user=cyrus argv=/cyrus/bin/deliver -e -m ${extension} ${user}
root@<redacted>-1:~# #
root@<redacted>-1:~# # ====================================================================
root@<redacted>-1:~# #
root@<redacted>-1:~# # See the Postfix UUCP_README file for configuration details.
root@<redacted>-1:~# #
root@<redacted>-1:~# uucp unix - n n - - pipe
The program 'uucp' is currently not installed. You can install it by typing:
apt-get install uucp
root@<redacted>-1:~# flags=Fqhu user=uucp argv=uux -r -n -z -a$sender - $nexthop!rmail ($recipient)
-bash: !rmail: event not found
root@<redacted>-1:~# #
root@<redacted>-1:~# # Other external delivery methods.
root@<redacted>-1:~# #
root@<redacted>-1:~# ifmail unix - n n - - pipe
ifmail: command not found
root@<redacted>-1:~# flags=F user=ftn argv=/usr/lib/ifmail/ifmail -r $nexthop ($recipient)
-bash: syntax error near unexpected token `('
root@<redacted>-1:~# bsmtp unix - n n - - pipe
The program 'bsmtp' is currently not installed. You can install it by typing:
apt-get install bacula-common
root@<redacted>-1:~# flags=Fq. user=bsmtp argv=/usr/lib/bsmtp/bsmtp -t$nexthop -f$sender $recipient
-t: command not found
root@<redacted>-1:~# scalemail-backend unix - n n - 2 pipe
scalemail-backend: command not found
root@<redacted>-1:~# flags=R user=scalemail argv=/usr/lib/scalemail/bin/scalemail-store ${nexthop} ${user} ${extension}
root@<redacted>-1:~# mailman unix - n n - - pipe
mailman: command not found
root@<redacted>-1:~# flags=FR user=list argv=/usr/lib/mailman/bin/postfix-to-mailman.py
root@<redacted>-1:~# ${nexthop} ${user}
No command 'list' found, did you mean: Command 'dist' from package 'nmh' (universe) Command 'lst' from package 'lustre-utils' (universe) Command 'slist' from package 'ncpfs' (universe) Command 'klist' from package 'heimdal-clients' (universe) Command 'klist' from package 'krb5-user' (universe) Command 'listg' from package 'nauty' (multiverse) Command 'hist' from package 'loki' (universe) Command 'flist' from package 'nmh' (universe) Command 'last' from package 'sysvinit-utils' (main) Command 'gist' from package 'yorick' (universe) Command 'bist' from package 'bist' (universe)
list: command not found
root@<redacted>-1:~# # SpamAssasin
root@<redacted>-1:~# spamassassin unix - n n - - pipe
The program 'spamassassin' is currently not installed. You can install it by typing:
apt-get install spamassassin
root@<redacted>-1:~# user=spamd argv=/usr/bin/spamc -f -e
-f: command not found
root@<redacted>-1:~# /usr/sbin/sendmail -oi -f ${sender} ${recipient}" > /etc/postfix/master.cf

What should I try next?

3 Answers

When using double-quoted strings you have to be very careful. If you want to avoid some special behaviour for example when using an exclamation mark, try using cat:

cat > /etc/postfix/master.cf <<EOF
#
# Postfix master process configuration file. For details on the format
# of the file, see the master(5) manual page (command: 'man 5 master').
#
# Do not forget to execute 'postfix reload' after editing this file.
#
# ==========================================================================
# service type private unpriv chroot wakeup maxproc command + args
# (yes) (yes) (yes) (never) (100)
# ==========================================================================
smtp inet n - - - - smtpd
#smtp inet n - - - 1 postscreen
#smtpd pass - - - - - smtpd
#dnsblog unix - - - - 0 dnsblog
#tlsproxy unix - - - - 0 tlsproxy
submission inet n - - - - smtpd -o content_filter=spamassassin -o syslog_name=postfix/submission -o smtpd_tls_security_level=encrypt -o smtpd_sasl_auth_enable=yes -o smtpd_client_restrictions=permit_sasl_authenticated,reject
# -o milter_macro_daemon_name=ORIGINATING
#smtps inet n - - - - smtpd
# -o syslog_name=postfix/smtps
# -o smtpd_tls_wrappermode=yes
# -o smtpd_sasl_auth_enable=yes
# -o smtpd_client_restrictions=permit_sasl_authenticated,reject
# -o milter_macro_daemon_name=ORIGINATING
#628 inet n - - - - qmqpd
pickup fifo n - - 60 1 pickup
cleanup unix n - - - 0 cleanup
qmgr fifo n - n 300 1 qmgr
#qmgr fifo n - n 300 1 oqmgr
tlsmgr unix - - - 1000? 1 tlsmgr
rewrite unix - - - - - trivial-rewrite
bounce unix - - - - 0 bounce
defer unix - - - - 0 bounce
trace unix - - - - 0 bounce
verify unix - - - - 1 verify
flush unix n - - 1000? 0 flush
proxymap unix - - n - - proxymap
proxywrite unix - - n - 1 proxymap
smtp unix - - - - - smtp
relay unix - - - - - smtp
# -o smtp_helo_timeout=5 -o smtp_connect_timeout=5
showq unix n - - - - showq
error unix - - - - - error
retry unix - - - - - error
discard unix - - - - - discard
local unix - n n - - local
virtual unix - n n - - virtual
lmtp unix - - - - - lmtp
anvil unix - - - - 1 anvil
scache unix - - - - 1 scache
#
# ====================================================================
# Interfaces to non-Postfix software. Be sure to examine the manual
# pages of the non-Postfix software to find out what options it wants.
#
# Many of the following services use the Postfix pipe(8) delivery
# agent. See the pipe(8) man page for information about ${recipient}
# and other message envelope options.
# ====================================================================
#
# maildrop. See the Postfix MAILDROP_README file for details.
# Also specify in main.cf: maildrop_destination_recipient_limit=1
#
maildrop unix - n n - - pipe flags=DRhu user=vmail argv=/usr/bin/maildrop -d ${recipient}
#
# ====================================================================
#
# Recent Cyrus versions can use the existing 'lmtp' master.cf entry.
#
# Specify in cyrus.conf:
# lmtp cmd='lmtpd -a' listen='localhost:lmtp' proto=tcp4
#
# Specify in main.cf one or more of the following:
# mailbox_transport = lmtp:inet:localhost
# virtual_transport = lmtp:inet:localhost
#
# ====================================================================
#
# Cyrus 2.1.5 (Amos Gouaux)
# Also specify in main.cf: cyrus_destination_recipient_limit=1
#
#cyrus unix - n n - - pipe
# user=cyrus argv=/cyrus/bin/deliver -e -r ${sender} -m ${extension} ${user}
#
# ====================================================================
# Old example of delivery via Cyrus.
#
#old-cyrus unix - n n - - pipe
# flags=R user=cyrus argv=/cyrus/bin/deliver -e -m ${extension} ${user}
#
# ====================================================================
#
# See the Postfix UUCP_README file for configuration details.
#
uucp unix - n n - - pipe flags=Fqhu user=uucp argv=uux -r -n -z -a$sender - $nexthop!rmail ($recipient)
#
# Other external delivery methods.
#
ifmail unix - n n - - pipe flags=F user=ftn argv=/usr/lib/ifmail/ifmail -r $nexthop ($recipient)
bsmtp unix - n n - - pipe flags=Fq. user=bsmtp argv=/usr/lib/bsmtp/bsmtp -t$nexthop -f$sender $recipient
scalemail-backend unix - n n - 2 pipe flags=R user=scalemail argv=/usr/lib/scalemail/bin/scalemail-store ${nexthop} ${user} ${extension}
mailman unix - n n - - pipe flags=FR user=list argv=/usr/lib/mailman/bin/postfix-to-mailman.py ${nexthop} ${user}
# SpamAssasin
spamassassin unix - n n - - pipe user=spamd argv=/usr/bin/spamc -f -e /usr/sbin/sendmail -oi -f ${sender} ${recipient}
EOF

Notice the error:

-bash: !rmail: event not found

That's interactive history expansion at work. Turn it off with

set +H

and retry the command. Re-enable it with set -H

The problem is that $VARNAME gets evaluated by bash inside double quotes. You'll need to escape and $'s with a \ like so: \$

Normally, you could just wrap the whole thing in single quotes, but because those are embedded in what you'd like to echo, you'd have to escape those too.

So you can either escape the single-qutoes or the $'s.

Or, just open up vi and type c]] before pasting everything in there and then following up with esc:wq.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like