刚才输入命令 echo "This is file content, over!" > filename 竟然会出错,提示:
bash: !": event not found
原来字符串中的!会被解析。如果不出错的话呢,转义!就可以了,如 \! ,
或者把双引号改成单引号也行。
Google了下错误信息,找到如下内容:
Message bash: !__: event not found
Notes When you type a word preceeded by an "!", bash thinks you want to recall a previous command or "event". The message indicates no matching event was found in your recent command history. You can suppress the special meaning of ! by quoting it, for example: \!
Notes When you type a word preceeded by an "!", bash thinks you want to recall a previous command or "event". The message indicates no matching event was found in your recent command history. You can suppress the special meaning of ! by quoting it, for example: \!
这段英文的大概意思就是说 !的作用就是调用之前的命令或事件。
比如 我之前输入了一条命令 touch aaa bbb ,然后又删了 rm aaa bbb,如果我又想重新创建文件aaa bbb 我直接输入 !touch 就可以了,该命令就会重复执行上一次touch命令,即touch aaa bbb
参考文献: