![为什么这个 echo 命令不起作用?](https://linux22.com/image/1423177/%E4%B8%BA%E4%BB%80%E4%B9%88%E8%BF%99%E4%B8%AA%20echo%20%E5%91%BD%E4%BB%A4%E4%B8%8D%E8%B5%B7%E4%BD%9C%E7%94%A8%EF%BC%9F.png)
我想/etc/postfix/master.cf
用自己的内容进行覆盖。我正在echo "<content>" > /etc/postfix/master.cf
尝试实现这一点。
但当我这样做时:
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
我收到很多错误:
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
下一步我应该尝试什么?
答案1
当使用双引用字符串你必须非常小心。如果你想避免某些特殊行为(例如使用感叹号),请尝试使用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
答案2
注意错误:
-bash: !rmail: event not found
这就是交互式历史扩展的作用。使用
set +H
并重试该命令。使用以下命令重新启用它set -H
答案3
问题是 $VARNAME 会被 bash 评估在双引号内。您需要使用 \ 来转义 $,如下所示:\$
通常情况下,您可以将整个内容用单引号引起来,但是由于这些内容嵌入在您想要回显的内容中,因此您也必须对其进行转义。
因此,您可以逃避单引号或$。
或者,只需打开 vi 并输入,c]]
然后粘贴所有内容,然后再跟进esc:wq
。