{"id":152,"date":"2014-06-26T03:18:40","date_gmt":"2014-06-26T03:18:40","guid":{"rendered":"http:\/\/ixyzero.com\/blog\/?p=152"},"modified":"2014-06-26T03:18:40","modified_gmt":"2014-06-26T03:18:40","slug":"%e8%ae%b0%e4%b8%80%e6%ac%a1shell%e8%84%9a%e6%9c%ac%e7%9a%84history%e9%97%ae%e9%a2%98%e5%88%86%e6%9e%90","status":"publish","type":"post","link":"https:\/\/ixyzero.com\/blog\/archives\/152.html","title":{"rendered":"\u8bb0\u4e00\u6b21shell\u811a\u672c\u7684history\u95ee\u9898\u5206\u6790"},"content":{"rendered":"<div><span style=\"color: #000000; font-size: medium;\">\u6700\u8fd1\u624d\u5f00\u59cb\u4e70VPS\u642d\u5efa\u4e2a\u4ebablog\u73a9\u73a9\uff0c\u867d\u8bf4\u65f6\u95f4\u4e0d\u662f\u5f88\u957f\uff0c\u4f46\u6211\u4e2a\u4eba\u89c9\u5f97\u5728\u8fd9\u6bb5\u6298\u817e\u7684\u65f6\u95f4\u91cc\uff0c\u4e2a\u4eba\u8fd8\u662f\u5b66\u5230\u4e86\u5f88\u591a\u4e1c\u897f\u7684\uff0c\u6bd4\u65b9\u8bf4\u5f88\u591ashell\u811a\u672c\u7684\u95ee\u9898\uff0c\u5f53\u4f60\u6ca1\u6709\u9047\u5230\u8fd9\u7c7b\u95ee\u9898\u7684\u65f6\u5019\uff0c\u5373\u4fbf\u4f60\u5f88\u806a\u660e\uff0c\u5728\u7b2c\u4e00\u6b21\u78b0\u5230\u8fd9\u4e2a\u95ee\u9898\u65f6\uff0c\u4e5f\u5f88\u96be\u4e0b\u624b\uff0c\u6bd4\u65b9\u8bf4\u8fd9\u6b21\u8bb0\u5f55\u7684\uff1a&#8221;\/bin\/sh: 1: history: not found&#8221;<\/span><\/div>\n<div><\/div>\n<div><span style=\"color: #000000; font-size: medium;\">\u56e0\u4e3a\u4e4b\u524d\u78b0\u5230\u8fc7\u51e0\u6b21VPS\u4e0d\u7a33\u5b9a{\u5176\u5b9e\u4e5f\u56e0\u4e3a\u6211\u559c\u6b22\u91cd\u88c5\u3001\u7f51\u7edc\u8fde\u63a5\u4e0d\u7a33\u5b9a\u3001\u5206\u6790\u95ee\u9898\u4e0d\u591f\u51b7\u9759\u5f7b\u5e95\u7b49\u539f\u56e0}\u800c\u5bfc\u81f4\u4e86\u6570\u636e\u7ecf\u5e38\u6027\u7684\u4e22\u5931\uff0c\u6709\u4e9b\u6570\u636eor\u5185\u5bb9\u56e0\u4e3a\u6709\u5907\u4efd\u4e22\u4e86\u8fd8\u4e0d\u7b97\u4ec0\u4e48\uff0c\u4f46\u662f\u6709\u4e9b\u5185\u5bb9\uff0c\u7279\u522b\u662f\u67d0\u4e9b\u53ea\u5728VPS\u4e0a\u4fee\u6539\u8fc7\u4e86\u7684\u811a\u672c\u4e22\u4e86\u90a3\u6211\u5c31\u975e\u5e38\u5fc3\u75db\u4e86\uff0c\u4e00\u6765\u662f\u6709\u4e9b\u4fee\u6539\u53ea\u6709\u5728\u5f53\u65f6\u7684\u73af\u5883\u4e2d\u624d\u4f1a\u5b58\u5728\uff0c\u5176\u6b21\u8fd9\u4e9b\u4fee\u6539\u771f\u7684\u662f\u4e00\u4e2a\u89e3\u51b3\u95ee\u9898\/\u96be\u9898\u7684\u8fc7\u7a0b\u8bb0\u5f55\uff0c\u4e22\u4e86\u7684\u8bdd\u5c31\u5f88\u96be\u627e\u56de\u6765\u4e86\uff0c\u5728\u75db\u5b9a\u601d\u75db\u4e4b\u540e\u6211\u51b3\u5b9a\u6bcf\u5929\u51cc\u6668\u7684\u65f6\u5019\u8fdb\u884c\u81ea\u52a8\u5907\u4efd{\u5c06\u4efb\u52a1\u5199\u5165crontab\u5c31\u884c}\uff0c\u5907\u4efd\u7684\u9664\u4e86\u811a\u672c\u8fd8\u6709\u6211\u4f7f\u7528putty\u8fdc\u7a0b\u767b\u9646\u8fc7\u7a0b\u4e2d\u6267\u884c\u8fc7\u7684\u547d\u4ee4\uff0c\u4fee\u6539\u4e86HISTTIMEFORMAT\u683c\u5f0f\uff08HISTTIMEFORMAT=&#8221;@%F_%T &#8220;;export HISTTIMEFORMAT\uff09\u4e4b\u540e\u8fd8\u662f\u663e\u5f97\u975e\u5e38\u76f4\u89c2\u7684\uff0c\u53ef\u4ee5\u6e05\u695a\u7684\u770b\u5230\u6211\u5728\u4ec0\u4e48\u65f6\u5019\u6267\u884c\u4e86\u4ec0\u4e48\u547d\u4ee4\uff0c\u4e0d\u8bba\u662f\u4e8b\u540e\u53d1\u73b0\u95ee\u9898\u8fd8\u662f\u5b89\u5168\u5ba1\u8ba1\uff0c\u8fd9\u90fd\u662f\u4e0d\u9519\u7684\u4e00\u4e2a\u6539\u8fdb\uff0c\u4f46\u662f\u95ee\u9898\u4e5f\u5c31\u968f\u4e4b\u800c\u6765\uff1a<\/span><\/div>\n<h6>\u7b2c\u4e00\u6b21\uff1a<\/h6>\n<div><span style=\"color: #000000; font-size: medium;\">\u76f4\u63a5\u5c06\u547d\u4ee4\u5199\u5165crontab\uff08\u8f93\u5165\u547d\u4ee4\uff1acrontab -e\u4e4b\u540e\uff0c\u7f16\u8f91\u5185\u5bb9\uff0c\u6dfb\u52a0\u4e00\u884c\u5185\u5bb9\uff1a59 23 * * * history | mutt <a href=\"mailto:xx@163.com\">xx@163.com<\/a> -s &#8220;history_bak&#8221;\uff0c\u4f46\u662f\u7b2c\u4e8c\u5929\u5728\u67e5\u770b\u90ae\u4ef6\u5185\u5bb9\u7684\u65f6\u5019\u53d1\u73b0\u662f\u7a7a\u7684\uff0c\u800c\u4e14\u5728&#8221;\/var\/mail\/root&#8221;\u4e2d\u6709\u4e00\u884c\u63d0\u793a\uff1a<span style=\"color: #ff0000;\"><strong>\/bin\/sh: 1: history: not found<\/strong><\/span>\uff09<\/span><\/div>\n<h6><span style=\"color: #000000; font-size: medium;\">\u7b2c\u4e8c\u6b21\uff1a<\/span><\/h6>\n<div><span style=\"color: #000000; font-size: medium;\">\u60f3\u7740\u5148\u5c06history\u7684\u5185\u5bb9\u5bfc\u51fa\u5230\u4e00\u4e2atxt\u6587\u4ef6\uff0c\u7136\u540e\u4ee5\u90ae\u4ef6\u9644\u4ef6\u7684\u5f62\u5f0f\u53d1\u9001\u51fa\u53bb\u3002\u4f46\u662f\uff0c\u4f9d\u65e7\u62a5\u9519\uff1a\/bin\/sh: 1: history: not found \u9644\u4ef6\u4e2d\u7684\u6587\u672c\u6587\u4ef6\u5185\u5bb9\u4e3a\u7a7a\u3002<\/span><\/div>\n<h6><span style=\"color: #000000; font-size: medium;\">\u7b2c\u4e09\u6b21\uff1a<\/span><\/h6>\n<div><span style=\"color: #000000; font-size: medium;\">\u51b3\u5fc3\u628a\u95ee\u9898\u6293\u51fa\u6765\uff0c\u4e8e\u662f\u5f00\u59cb\u641c\u7d22\uff1a<\/span><\/div>\n<ul>\n<li>site:stackoverflow.com \/bin\/sh: 1: history: not found<\/li>\n<li>ubuntu bash history no output site:stackoverflow.com<\/li>\n<\/ul>\n<div>\u7ec8\u4e8e\u5728\u4ee5\u4e0b\u5185\u5bb9\u4e2d\u627e\u5230\u4e86\u95ee\u9898\u6240\u5728\uff1a<\/div>\n<div><a href=\"http:\/\/stackoverflow.com\/questions\/10957664\/ssh-host-history-tail-produces-no-output\" target=\"_blank\">http:\/\/stackoverflow.com\/questions\/10957664\/ssh-host-history-tail-produces-no-output<\/a><\/div>\n<div><\/div>\n<div>History is not loaded for a non-interactive shell.\uff08<strong><span style=\"color: #ff0000;\">history\u547d\u4ee4\u5728\u975e\u4ea4\u4e92\u5f0fshell\u7684\u60c5\u51b5\u4e0b\u662f\u6ca1\u6709\u52a0\u8f7d\u7684<\/span><\/strong>\uff09 You can either\u00a0<code>tail<\/code>\u00a0the history file (<code>~\/.bash_history<\/code>) or turn on history and load it.<\/div>\n<div>\n<pre class=\"lang:default decode:true\">set -o history\nhistory -r<\/pre>\n<\/div>\n<div>\n<p style=\"color: #000000;\">The full commands needed to do this from the remote host is as follows:<\/p>\n<pre class=\"lang:default decode:true\">ssh host 'HISTFILE=~\/.bash_history; history -r; history' | tail<\/pre>\n<\/div>\n<div><span style=\"color: #000000; font-size: medium;\">\u5373\uff0chistory\u547d\u4ee4\u65e0\u6cd5\u5728\u4e00\u4e2a\u975e\u4ea4\u4e92\u5f0f\u7684shell\u4e2d\u6267\u884c\uff0c\u6240\u4ee5\uff0c\u5982\u679c\u60f3\u8981\u8fbe\u5230\u6211\u7684\u76ee\u7684\uff0c\u6709<span style=\"color: #ff0000;\"><strong>\u4e24\u79cd\u65b9\u6cd5<\/strong><\/span>\uff1a<\/span><\/div>\n<ol>\n<li><span style=\"color: #000000; font-size: medium;\">\u76f4\u63a5\u4f7f\u7528~\/.bash_history\u6587\u4ef6\u5185\u5bb9\uff0c\u4f46\u56e0\u4e3a\u6211\u6dfb\u52a0\u4e86\u547d\u4ee4\u6267\u884c\u65f6\u95f4\u6233\u7684\u529f\u80fd\uff0c\u6587\u4ef6\u4e2d\u663e\u793a\u7684\u65f6\u95f4\u662fUnix\u683c\u5f0f\u7684\uff0c\u4e0d\u76f4\u89c2\uff0c\u6240\u4ee5\u6682\u65f6\u4e0d\u63a8\u8350\uff1b<\/span><\/li>\n<li><span style=\"color: #000000; font-size: medium;\">\u5728\u975e\u4ea4\u4e92\u5f0fshell\u4e2d\u52a0\u8f7d\/\u6253\u5f00history\u547d\u4ee4\uff0c\u4f7f\u7528&#8221;set -o history&#8221;\u547d\u4ee4\uff08\u5982\u679c\u7ecf\u5e38\u6027\u9700\u8981\uff0c\u53ef\u4ee5\u5c06\u5b83\u6dfb\u52a0\u5230\/etc\/rc.local\u6216~\/.bashrc\u4e2d\uff09\u3002<\/span><\/li>\n<\/ol>\n<div><span style=\"color: #000000; font-size: medium;\">\u7b2c\u4e8c\u79cd\u65b9\u6cd5\u7684\u4e00\u4e2a\u793a\u4f8b\uff1a<\/span><\/div>\n<div><a href=\"http:\/\/ixyzero.com\/blog\/wp-content\/uploads\/2014\/06\/history_in_nonloginShell.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\" size-medium wp-image-153 aligncenter\" src=\"http:\/\/ixyzero.com\/blog\/wp-content\/uploads\/2014\/06\/history_in_nonloginShell-300x129.jpg\" alt=\"history_in_nonloginShell\" width=\"300\" height=\"129\" \/><\/a><\/div>\n<div style=\"text-align: center;\">\u5728\u811a\u672c\u5185\u90e8\u6dfb\u52a0\u4e86&#8221;set -o history&#8221;\u547d\u4ee4<\/div>\n<div><\/div>\n<div>\u5982\u679c\u5168\u5c40\u6dfb\u52a0&#8221;set -o history&#8221;\u547d\u4ee4\u7684\u8bdd\uff0c\u4f30\u8ba1\u5b89\u5168\u6027\u662f\u4e2a\u5f88\u5927\u7684\u95ee\u9898\uff08<span style=\"color: #ff0000;\">\u9ed8\u8ba4\u60c5\u51b5\u4e0bhistory\u547d\u4ee4\u8bb0\u5f55\u7684\u90fd\u662f\u4ea4\u4e92\u5f0fshell\u4e2d\u6267\u884c\u7684\u547d\u4ee4\u5217\u8868\uff0c\u800cshell\u811a\u672c\u4e2d\u7684\u547d\u4ee4\u6267\u884c\u5c5e\u4e8e\u975e\u4ea4\u4e92\u5f0f\u7684\uff0c\u6240\u4ee5\uff0c\u6267\u884cshell\u811a\u672c\u65f6\uff0c\u811a\u672c\u91cc\u9762\u6267\u884c\u7684\u547d\u4ee4\u4e0d\u4f1a\u51fa\u73b0\u5728history\u547d\u4ee4\u663e\u793a\u7684\u7ed3\u679c\u4e2d<\/span>\uff09\uff0c\u6240\u4ee5\uff0c\u60f3\u60f3\u6211\u8fd8\u662f\u7b97\u4e86\u5427\uff0c\u4f7f\u7528~\/.bash_history\u6587\u4ef6\u4e5f\u53ef\u4ee5\u7684\u3002<\/div>\n<div><\/div>\n<ul>\n<li><a href=\"http:\/\/unix.stackexchange.com\/questions\/89006\/why-is-the-bash-history-always-coming-up-the-same-and-not-updating-using-non-log\" target=\"_blank\">bash &#8211; Why is the bash_history always coming up the same and <span style=\"color: #ff0000;\">not updating using non-login shells<\/span>?<\/a><\/li>\n<li><a href=\"http:\/\/www.gnu.org\/software\/bash\/manual\/html_node\/The-Set-Builtin.html#The-Set-Builtin\" target=\"_blank\">Bash Reference Manual: The Set Builtin<\/a><\/li>\n<li><span style=\"color: #ff0000;\"><a href=\"http:\/\/www.gnu.org\/software\/bash\/manual\/html_node\/Bash-History-Facilities.html#Bash-History-Facilities\" target=\"_blank\">Bash Reference Manual: Bash History Facilities<\/a><\/span><\/li>\n<\/ul>\n<div><span style=\"color: #000000; font-size: medium;\">================================================<\/span><\/div>\n<h5><span style=\"color: #000000; font-size: medium;\">\u5728\u627e\u5230\u7b54\u6848\u4e4b\u524d\u8d70\u7684\u4e00\u4e9b\u5f2f\u8def\uff1a<\/span><\/h5>\n<h6>\u5173\u4e8e-\/bin\/sh:xx(\u547d\u4ee4) not found \u7684\u51e0\u79cd\u539f\u56e0\uff1a<\/h6>\n<div>\n<ul>\n<li style=\"color: #333333;\">$PATH\u4e0b\u6ca1\u6709\u8fd9\u4e2a\u547d\u4ee4\uff1b<\/li>\n<li style=\"color: #333333;\">$PATH\u4e0b\u6709\u8fd9\u4e2a\u547d\u4ee4\uff0c\u53ea\u662f\u6267\u884c\u6743\u9650\u4e0d\u591f\uff0c\u6216\u8005\u7a0b\u5e8f\u6267\u884c\u6743\u9650\u4e0d\u591f\uff1b<\/li>\n<li style=\"color: #333333;\">\u7a0b\u5e8f\u9700\u8981\u7684\u9759\u6001\u5e93\u6216\u8005\u52a8\u6001\u5e93\u6ca1\u6709\u3002<\/li>\n<\/ul>\n<\/div>\n<div><span style=\"color: #000000; font-size: medium;\">\u4e0a\u9762\u7684\u5185\u5bb9\u4e00\u770b\u5176\u5b9e\u662f\u975e\u5e38\u6709\u9053\u7406\u7684\uff0c\u4f46\u662f\uff0c\u521a\u5f00\u59cb\u6211\u4e5f\u5c31\u8fd9\u4e48\u88ab\u5e26\u8fdb\u6c9f\u91cc\u9762\u4e86o(\u256f\u25a1\u2570)o<\/span><\/div>\n<h6><span style=\"color: #000000; font-size: medium;\">\u67e5\u627ehistory\u6587\u4ef6\uff1a<\/span><\/h6>\n<div>\n<pre class=\"lang:default decode:true\"># find \/ -name history #\u6ca1\u6709\u4efb\u4f55\u8f93\u51fa{\u5728\u6211\u7684Ubuntu12.04 x32\u7cfb\u7edf\u4e0a\n# man history  #\u6ca1\u6709-r\u9009\u9879\n# man bash  #\u8fd9\u91cc\u9762\u7684\u5185\u5bb9\u6bd4\u8f83\u591a\uff0c\u4f46\u662f\u4e5f\u786e\u5b9e\u592a\u591a\u4e86\u2026\u2026<\/pre>\n<\/div>\n<div><span style=\"color: #000000; font-size: medium;\">\u540e\u6765\u5728\u641c\u7d22\u7684\u8fc7\u7a0b\u4e2d\uff0c\u624d\u60f3\u5230\uff1a\u56e0\u4e3ahistory\u547d\u4ee4\u5c5e\u4e8eLinux\u7684\u5185\u5efa(built-in)\u547d\u4ee4\uff0c\u7528find\u67e5\u627e\u4e0d\u5230\u4e5f\u5c31\u5f88\u6b63\u5e38\u4e86\uff08\u5173\u4e8e\u5982\u4f55\u77e5\u9053Linux\u6709\u54ea\u4e9b\u5185\u5efa\u547d\u4ee4\uff0c\u8bf7\u81ea\u884c\u641c\u7d22or\u7ffb\u81f3\u6587\u7ae0\u6700\u5e95\u90e8\uff09<\/span><\/div>\n<h5><span style=\"color: #000000; font-size: medium;\">\u4e00\u4e9b\u53c2\u8003\u94fe\u63a5\uff1a<\/span><\/h5>\n<ul>\n<li><a href=\"http:\/\/blog.sina.com.cn\/s\/blog_7cb1c50e0100rapz.html\" target=\"_blank\">Shell\u00a0\u811a\u672c\u65f6\u663e\u793adeclare\u00a0not\u00a0found\u7684\u95ee\u9898<\/a><\/li>\n<li><a href=\"http:\/\/blog.csdn.net\/tangy110\/article\/details\/6278259\" target=\"_blank\">\u6267\u884cshell\u811a\u672c\u4e2ddeclare: not found<\/a><\/li>\n<li><a href=\"http:\/\/www.cnblogs.com\/Trekshot\/archive\/2010\/03\/29\/ubuntu-shell-bash-dash.html\" target=\"_blank\">Ubuntu \u4e0b\u8fd0\u884c Shell \u811a\u672c\u65f6\u663e\u793a &#8220;declare not found&#8221; \u7684\u95ee\u9898<\/a><\/li>\n<li><span style=\"color: #000000; font-size: medium;\"><a href=\"http:\/\/www.cnblogs.com\/philander\/archive\/2010\/11\/14\/1876842.html\" target=\"_blank\">&#8220;source:not found&#8221; in Ubuntu10.10<\/a><\/span><\/li>\n<li><a href=\"http:\/\/stackoverflow.com\/questions\/12468889\/bash-script-error-function-not-found-why-would-this-appear\" target=\"_blank\">http:\/\/stackoverflow.com\/questions\/12468889\/bash-script-error-function-not-found-why-would-this-appear<\/a><\/li>\n<li><a href=\"http:\/\/stackoverflow.com\/questions\/13702425\/source-command-not-found-in-sh-shell\" target=\"_blank\">http:\/\/stackoverflow.com\/questions\/13702425\/source-command-not-found-in-sh-shell<\/a><\/li>\n<\/ul>\n<div><\/div>\n<div>====<\/div>\n<h6><span style=\"color: #000000; font-size: medium;\"><a href=\"http:\/\/blog.sina.com.cn\/s\/blog_8bb0a3bd010171cp.html\" target=\"_blank\">linux\u4e2d\u7684set\u547d\u4ee4:&#8221;set -e&#8221;\u4e0e&#8221;set -o pipefail&#8221;<\/a><\/span><\/h6>\n<div><span style=\"color: #000000; font-size: medium;\"><span style=\"color: #555555;\">\u5de5\u4f5c\u4e2d\u7ecf\u5e38\u5728shell\u811a\u672c\u4e2d\u770b\u5230set\u7684\u8fd9\u4e24\u4e2a\u7528\u6cd5\uff0c\u4f46<strong><span style=\"color: #ff0000;\">\u5c31\u50cf\u751f\u6d3b\u4e2d\u7684\u5f88\u591a\u4e8b\u60c5\uff0c\u4e60\u60ef\u5bfc\u81f4\u5ffd\u89c6\uff0c\u76f4\u5230\u51fa\u73b0\u95ee\u9898\u624d\u5f15\u8d77<\/span><\/strong><\/span><span style=\"color: #555555;\"><strong><span style=\"color: #ff0000;\">\u5173\u6ce8<\/span><\/strong>\u3002<\/span><\/span><\/div>\n<h6><span style=\"color: #000000; font-size: medium;\"><span style=\"color: #555555;\">1. set -e<\/span><\/span><\/h6>\n<div><span style=\"color: #000000; font-size: medium;\"><span style=\"color: #555555;\">set\u547d\u4ee4\u7684-e\u53c2\u6570\uff0cLinux\u4e2d\u7684\u8bf4\u660e\u5982\u4e0b\uff1a<\/span><\/span><\/div>\n<div style=\"padding-left: 30px;\"><span style=\"color: #000000; font-size: medium;\"><span style=\"font-style: italic; color: #ff0000;\">&#8220;Exit immediately if a simple command exits with a non-zero status.&#8221;<\/span><\/span><\/div>\n<div><span style=\"color: #000000; font-size: medium;\"><span style=\"color: #555555;\">\u4e5f\u5c31\u662f\u8bf4\uff0c\u5728&#8221;set -e&#8221;\u4e4b\u540e\u51fa\u73b0\u7684\u4ee3\u7801\uff0c\u4e00\u65e6\u51fa\u73b0\u4e86\u8fd4\u56de\u503c\u975e\u96f6\uff0c\u6574\u4e2a\u811a\u672c\u5c31\u4f1a\u7acb\u5373\u9000\u51fa\u3002\u6709\u7684\u4eba\u559c\u6b22\u4f7f\u7528\u8fd9\u4e2a\u53c2\u6570\uff0c\u662f\u51fa\u4e8e\u4fdd\u8bc1\u4ee3\u7801\u5b89\u5168\u6027\u7684\u8003\u8651\u3002\u4f46\u6709\u7684\u65f6\u5019\uff0c\u8fd9\u79cd\u7f8e\u597d\u7684\u521d\u8877\uff0c\u4e5f\u4f1a\u5bfc\u81f4\u4e25\u91cd\u7684\u95ee\u9898\u3002<\/span><\/span><\/div>\n<h6><span style=\"color: #000000; font-size: medium;\"><span style=\"color: #555555;\">2. set -o pipefail<\/span><\/span><\/h6>\n<div><span style=\"color: #000000; font-size: medium;\"><span style=\"color: #555555;\">\u5bf9\u4e8eset\u547d\u4ee4-o\u53c2\u6570\u7684pipefail\u9009\u9879\uff0cLinux\u91cc\u662f\u8fd9\u6837\u89e3\u91ca\u7684\uff1a<\/span><\/span><\/div>\n<div style=\"padding-left: 30px;\"><span style=\"color: #000000; font-size: medium;\"><span style=\"color: #555555;\">&#8220;If set, the return value of a pipeline is the value of the last (rightmost) command to exit with a\u00a0<wbr \/>\u00a0non-zero\u00a0<wbr \/>\u00a0status,or zero if all commands in the pipeline exit successfully.\u00a0<wbr \/>\u00a0This option is disabled by default.&#8221;<\/span><\/span><\/div>\n<div><span style=\"color: #000000; font-size: medium;\"><span style=\"color: #555555;\">\u8bbe\u7f6e\u4e86\u8fd9\u4e2a\u9009\u9879\u4ee5\u540e\uff0c\u5305\u542b\u7ba1\u9053\u547d\u4ee4\u7684\u8bed\u53e5\u7684\u8fd4\u56de\u503c\uff0c\u4f1a\u53d8\u6210\u6700\u540e\u4e00\u4e2a\u8fd4\u56de\u975e\u96f6\u7684\u7ba1\u9053\u547d\u4ee4\u7684\u8fd4\u56de\u503c\u3002\u542c\u8d77\u6765\u6bd4\u8f83\u7ed5\uff0c\u5176\u5b9e\u4e5f\u5f88\u7b80\u5355\uff1a<\/span><br \/>\n<\/span><\/div>\n<div>\n<pre class=\"lang:default decode:true\">$ vim set_o_pipefail.sh\n$ cat set_o_pipefail.sh\n#!\/bin\/bash\nset -o pipefail\nls .\/a.txt |echo \"hi\" &gt;\/dev\/null\necho $?\n$\n$ bash set_o_pipefail.sh\nls: cannot access .\/a.txt: No such file or directory\n2\n$\n$ vim set_o_pipefail.sh\n$ cat set_o_pipefail.sh\n#!\/bin\/bash\n#set -o pipefail\nls .\/a.txt |echo \"hi\" &gt;\/dev\/null\necho $?\n$\n$ bash set_o_pipefail.sh\nls: cannot access .\/a.txt: No such file or directory\n0\n$<\/pre>\n<\/div>\n<div>\n<dl compact=\"compact\">\n<dd><strong>\u53c2\u8003\u6587\u7ae0<\/strong>\uff1a<a href=\"http:\/\/www.gnu.org\/software\/bash\/manual\/html_node\/The-Set-Builtin.html#The-Set-Builtin\" target=\"_blank\">Bash Reference Manual: The Set Builtin<\/a><\/dd>\n<dd><strong><span style=\"color: #ff0000;\">\u4e00\u4e2a\u5173\u4e8ehistory\u547d\u4ee4\u4f7f\u7528\u65b9\u6cd5\u7684\u8d85\u8d5e\u6587\u7ae0<\/span><\/strong>\uff1a<\/dd>\n<dd><a href=\"http:\/\/www.thegeekstuff.com\/2008\/08\/15-examples-to-master-linux-command-line-history\/\" target=\"_blank\">15 Examples To Master Linux Command Line History<\/a><\/dd>\n<\/dl>\n<\/div>\n<div>In the example below, the\u00a0<strong>!^<\/strong>\u00a0next to the vi command gets the first argument from the previous command (i.e cp command) to the current command (i.e vi command).<\/div>\n<div>\n<pre style=\"color: #111111;\"># <strong>cp anaconda-ks.cfg anaconda-ks.cfg.bak<\/strong>\nanaconda-ks.cfg\n# <strong>vi  !^<\/strong>\nvi anaconda-ks.cfg<\/pre>\n<\/div>\n<div><span style=\"color: #000000; font-size: medium;\">\u8fd9\u4e2a<strong><span style=\"color: #ff0000;\">\u83b7\u53d6\u4e0a\u4e2a\u547d\u4ee4\u7684\u7b2c\u4e00\u4e2a\u53c2\u6570<\/span><\/strong>\u7684\u65b9\u6cd5\u592a\u6709\u7528\u4e86\uff0c\u68a6\u91cc\u5bfb\u4ed6\u5343\u767e\u5ea6\uff0c\u84e6\u7136\u56de\u9996\uff0c\u90a3\u4eba\u5374\u5728\u706f\u706b\u9611\u73ca\u5904\uff01<\/span><\/div>\n<div><a href=\"http:\/\/ixyzero.com\/blog\/wp-content\/uploads\/2014\/06\/history__firstArgument.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-154\" src=\"http:\/\/ixyzero.com\/blog\/wp-content\/uploads\/2014\/06\/history__firstArgument-300x100.jpg\" alt=\"history__firstArgument\" width=\"300\" height=\"100\" \/><\/a><\/div>\n<h6>\u5982\u4f55\u5224\u65ad\u4e00\u4e2a\u547d\u4ee4\u662f\u5426\u4e3aLinux\u7684\u5185\u5efa\u547d\u4ee4\uff08\u5373\uff0c\u5982\u4f55\u83b7\u53d6Linux\u7cfb\u7edf\u7684bash\u7684\u5185\u5efa\u547d\u4ee4\u5217\u8868\uff09\uff1a<\/h6>\n<ul>\n<li><a href=\"http:\/\/www.gnu.org\/software\/bash\/manual\/bashref.html#Shell-Builtin-Commands\">http:\/\/www.gnu.org\/software\/bash\/manual\/bashref.html#Shell-Builtin-Commands<\/a><\/li>\n<li>site:stackoverflow.com linux builtin commands<\/li>\n<li><a href=\"http:\/\/stackoverflow.com\/questions\/3192373\/what-are-shell-built-in-commands-in-linux\">http:\/\/stackoverflow.com\/questions\/3192373\/what-are-shell-built-in-commands-in-linux<\/a><\/li>\n<li><a href=\"http:\/\/stackoverflow.com\/questions\/6103232\/how-to-get-bash-built-in-commands-using-perl\">http:\/\/stackoverflow.com\/questions\/6103232\/how-to-get-bash-built-in-commands-using-perl<\/a><\/li>\n<li><a href=\"http:\/\/stackoverflow.com\/questions\/511683\/bash-get-list-of-commands-starting-with-a-given-string\">http:\/\/stackoverflow.com\/questions\/511683\/bash-get-list-of-commands-starting-with-a-given-string<\/a><\/li>\n<\/ul>\n<div><strong><span style=\"color: #ff0000;\">Linux\u7cfb\u7edf\u67e5\u770b\u547d\u4ee4\u662f\u4e0d\u662f\u5185\u5efa\u547d\u4ee4<\/span><\/strong>\u201ctype\u201d<\/div>\n<div><a href=\"http:\/\/blog.csdn.net\/sahusoft\/article\/details\/4428819\" target=\"_blank\">\u4f7f\u7528type\u547d\u4ee4\u8fdb\u884c\u5224\u65ad<\/a>\uff1a<\/div>\n<div>\n<pre class=\"lang:default decode:true\"># type history\nhistory is a shell builtin<\/pre>\n<\/div>\n<div><span style=\"color: #000000; font-size: medium;\">\u5728\u89e3\u51b3\u95ee\u9898\u7684\u8fc7\u7a0b\u4e2d\u6d4f\u89c8\u8fc7\u7684\u7f51\u9875\u3001\u641c\u7d22\u8fc7\u7684\u5173\u952e\u5b57\u771f\u7684\u662f\u4e00\u4e2a\u4e0d\u53ef\u591a\u5f97\u7684\u7ecf\u9a8c\u8d22\u5bcc\uff01<\/span><\/div>\n<div><\/div>\n<div><span style=\"color: #000000; font-size: medium;\">@2014\u5e746\u670823\u65e5 12:57:02<\/span><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u6700\u8fd1\u624d\u5f00\u59cb\u4e70VPS\u642d\u5efa\u4e2a\u4ebablog\u73a9\u73a9\uff0c\u867d\u8bf4\u65f6\u95f4\u4e0d\u662f\u5f88\u957f\uff0c\u4f46\u6211\u4e2a\u4eba\u89c9\u5f97\u5728\u8fd9\u6bb5\u6298\u817e\u7684\u65f6\u95f4\u91cc\uff0c\u4e2a\u4eba\u8fd8\u662f\u5b66\u5230\u4e86\u5f88\u591a\u4e1c [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23,11,6],"tags":[91,92],"class_list":["post-152","post","type-post","status-publish","format-standard","hentry","category-knowledgebase-2","category-linux","category-other","tag-dpkg-reconfigure","tag-history"],"views":6849,"_links":{"self":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/152","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/comments?post=152"}],"version-history":[{"count":0,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/152\/revisions"}],"wp:attachment":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/media?parent=152"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/categories?post=152"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/tags?post=152"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}