{"id":1663,"date":"2017-01-15T10:08:36","date_gmt":"2017-01-15T02:08:36","guid":{"rendered":"http:\/\/cn.hostease.com\/xueyuan\/?p=1663"},"modified":"2017-01-15T10:08:36","modified_gmt":"2017-01-15T02:08:36","slug":"linux-%e4%b9%8b-etcprofile%e3%80%81-bash_profile-%e7%ad%89%e5%87%a0%e4%b8%aa%e6%96%87%e4%bb%b6%e7%9a%84%e6%89%a7%e8%a1%8c%e8%bf%87%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/cn.hostease.com\/xueyuan\/jishu\/linux-%e4%b9%8b-etcprofile%e3%80%81-bash_profile-%e7%ad%89%e5%87%a0%e4%b8%aa%e6%96%87%e4%bb%b6%e7%9a%84%e6%89%a7%e8%a1%8c%e8%bf%87%e7%a8%8b\/","title":{"rendered":"Linux \u4e4b \/etc\/profile\u3001~\/.bash_profile \u7b49\u51e0\u4e2a\u6587\u4ef6\u7684\u6267\u884c\u8fc7\u7a0b"},"content":{"rendered":"<div class=\"post-bd fz16\">\n<p>\u5728\u767b\u5f55<span class=\"wp_keywordlink\"><a title=\"Linux\" href=\"https:\/\/www.linuxde.net\" target=\"_blank\">Linux<\/a><\/span>\u65f6\u8981\u6267\u884c\u6587\u4ef6\u7684\u8fc7\u7a0b\u5982\u4e0b\uff1a<\/p>\n<p>\u5728\u521a\u767b\u5f55Linux\u65f6\uff0c\u9996\u5148\u542f\u52a8 \/etc\/profile \u6587\u4ef6\uff0c\u7136\u540e\u518d\u542f\u52a8\u7528\u6237\u76ee\u5f55\u4e0b\u7684 ~\/.bash_profile\u3001 ~\/.bash_login\u6216 ~\/.profile\u6587\u4ef6\u4e2d\u7684\u5176\u4e2d\u4e00\u4e2a\uff0c<\/p>\n<p>\u6267\u884c\u7684\u987a\u5e8f\u4e3a\uff1a~\/.bash_profile\u3001 ~\/.bash_login\u3001 ~\/.profile\u3002<\/p>\n<p>\u5982\u679c ~\/.bash_profile\u6587\u4ef6\u5b58\u5728\u7684\u8bdd\uff0c\u4e00\u822c\u8fd8\u4f1a\u6267\u884c ~\/.bashrc\u6587\u4ef6\u3002<\/p>\n<p>\u56e0\u4e3a\u5728 ~\/.bash_profile\u6587\u4ef6\u4e2d\u4e00\u822c\u4f1a\u6709\u4e0b\u9762\u7684\u4ee3\u7801\uff1a<\/p>\n<pre>if [ -f ~\/.bashrc ] ; then\r\n. .\/bashrc\r\nfi<\/pre>\n<p>~\/.bashrc\u4e2d\uff0c\u4e00\u822c\u8fd8\u4f1a\u6709\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n<pre>if [ -f \/etc\/bashrc ] ; then\r\n. \/etc\/bashrc\r\nfi<\/pre>\n<p>\u6240\u4ee5\uff0c~\/.bashrc\u4f1a\u8c03\u7528 \/etc\/bashrc\u6587\u4ef6\u3002\u6700\u540e\uff0c\u5728\u9000\u51fa<span class=\"wp_keywordlink\"><a title=\"Shell\" href=\"https:\/\/www.linuxde.net\/tag\/shell\" target=\"_blank\">Shell<\/a><\/span>\u65f6\uff0c\u8fd8\u4f1a\u6267\u884c ~\/.bash_logout\u6587\u4ef6\u3002<\/p>\n<p>\u6267\u884c\u987a\u5e8f\u4e3a\uff1a \/etc\/profile -&gt; (~\/.bash_profile | ~\/.bash_login | ~\/.profile) -&gt; ~\/.bashrc -&gt; \/etc\/bashrc -&gt; ~\/.bash_logout<\/p>\n<p>\u5173\u4e8e\u5404\u4e2a\u6587\u4ef6\u7684\u4f5c\u7528\u57df\uff0c\u5728\u7f51\u4e0a\u627e\u5230\u4e86\u4ee5\u4e0b\u8bf4\u660e\uff1a<\/p>\n<p>\uff081\uff09 \/etc\/profile\uff1a \u6b64\u6587\u4ef6\u4e3a\u7cfb\u7edf\u7684\u6bcf\u4e2a\u7528\u6237\u8bbe\u7f6e\u73af\u5883\u4fe1\u606f,\u5f53\u7528\u6237\u7b2c\u4e00\u6b21\u767b\u5f55\u65f6,\u8be5\u6587\u4ef6\u88ab\u6267\u884c. \u5e76\u4ece\/etc\/profile.d\u76ee\u5f55\u7684\u914d\u7f6e\u6587\u4ef6\u4e2d\u641c\u96c6shell\u7684\u8bbe\u7f6e\u3002<\/p>\n<p>\uff082\uff09 \/etc\/bashrc: \u4e3a\u6bcf\u4e00\u4e2a\u8fd0\u884cbash shell\u7684\u7528\u6237\u6267\u884c\u6b64\u6587\u4ef6.\u5f53bash shell\u88ab\u6253\u5f00\u65f6,\u8be5\u6587\u4ef6\u88ab\u8bfb\u53d6\uff08\u5373\u6bcf\u6b21\u65b0\u5f00\u4e00\u4e2a\u7ec8\u7aef\uff0c\u90fd\u4f1a\u6267\u884cbashrc\uff09\u3002<\/p>\n<p>\uff083\uff09 ~\/.bash_profile:\u00a0\u6bcf\u4e2a\u7528\u6237\u90fd\u53ef\u4f7f\u7528\u8be5\u6587\u4ef6\u8f93\u5165\u4e13\u7528\u4e8e\u81ea\u5df1\u4f7f\u7528\u7684shell\u4fe1\u606f,\u5f53\u7528\u6237\u767b\u5f55\u65f6,\u8be5\u6587\u4ef6\u4ec5\u4ec5\u6267\u884c\u4e00\u6b21\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b,\u8bbe\u7f6e\u4e00\u4e9b\u73af\u5883\u53d8\u91cf,\u6267\u884c\u7528\u6237\u7684.bashrc\u6587\u4ef6\u3002<\/p>\n<p>\uff084\uff09 ~\/.bashrc:\u00a0\u8be5\u6587\u4ef6\u5305\u542b\u4e13\u7528\u4e8e\u4f60\u7684bash shell\u7684bash\u4fe1\u606f,\u5f53\u767b\u5f55\u65f6\u4ee5\u53ca\u6bcf\u6b21\u6253\u5f00\u65b0\u7684shell\u65f6,\u8be5\u8be5\u6587\u4ef6\u88ab\u8bfb\u53d6\u3002<\/p>\n<p>\uff085\uff09 ~\/.bash_logout: \u5f53\u6bcf\u6b21\u9000\u51fa\u7cfb\u7edf(\u9000\u51fabash shell)\u65f6,\u6267\u884c\u8be5\u6587\u4ef6.\u00a0\u53e6\u5916,\/etc\/profile\u4e2d\u8bbe\u5b9a\u7684\u53d8\u91cf(\u5168\u5c40)\u7684\u53ef\u4ee5\u4f5c\u7528\u4e8e\u4efb\u4f55\u7528\u6237,\u800c~\/.bashrc\u7b49\u4e2d\u8bbe\u5b9a\u7684\u53d8\u91cf(\u5c40\u90e8)\u53ea\u80fd\u7ee7\u627f \/etc\/profile\u4e2d\u7684\u53d8\u91cf,\u4ed6\u4eec\u662f&#8221;\u7236\u5b50&#8221;\u5173\u7cfb\u3002<\/p>\n<p>\uff086\uff09 ~\/.bash_profile:\u00a0\u662f\u4ea4\u4e92\u5f0f\u3001<span class=\"wp_keywordlink\"><a title=\"login\u547d\u4ee4\" href=\"https:\/\/man.linuxde.net\/login\" target=\"_blank\">login<\/a><\/span> \u65b9\u5f0f\u8fdb\u5165 bash \u8fd0\u884c\u7684~\/.bashrc \u662f\u4ea4\u4e92\u5f0f non-login \u65b9\u5f0f\u8fdb\u5165 bash \u8fd0\u884c\u7684\u901a\u5e38\u4e8c\u8005\u8bbe\u7f6e\u5927\u81f4\u76f8\u540c\uff0c\u6240\u4ee5\u901a\u5e38\u524d\u8005\u4f1a\u8c03\u7528\u540e\u8005\u3002<\/p>\n<p>\/etc\/profile\u548c\/etc\/environment\u7b49\u5404\u79cd\u73af\u5883\u53d8\u91cf\u8bbe\u7f6e\u6587\u4ef6\u7684\u7528\u5904<\/p>\n<p>1\uff09\u5148\u5c06<span class=\"wp_keywordlink\"><a title=\"export\u547d\u4ee4\" href=\"https:\/\/man.linuxde.net\/export\" target=\"_blank\">export<\/a><\/span> LANG=zh_CN\u52a0\u5165\/etc\/profile\uff0c\u9000\u51fa\u7cfb\u7edf\u91cd\u65b0\u767b\u5f55\uff0c\u767b\u5f55\u63d0\u793a\u663e\u793a\u82f1\u6587\u3002<\/p>\n<p>2\uff09\u5148\u5c06\/etc\/profile \u4e2d\u7684export LANG=zh_CN\u5220\u9664\uff0c\u5c06LNAG=zh_CN\u52a0\u5165\/etc\/environment\uff0c\u9000\u51fa\u7cfb\u7edf\u91cd\u65b0\u767b\u5f55\uff0c\u767b\u5f55\u63d0\u793a\u663e\u793a\u4e2d\u6587\u3002<\/p>\n<p>\u7528\u6237\u73af\u5883\u5efa\u7acb\u7684\u8fc7\u7a0b\u4e2d\u603b\u662f\u5148\u6267\u884c\/etc\/profile\uff0c\u7136\u540e\u518d\u8bfb\u53d6\/etc\/environment\u3002\u4e3a\u4ec0\u4e48\u4f1a\u6709\u5982\u4e0a\u6240\u53d9\u7684\u4e0d\u540c\u5462\uff1f\u800c\u4e0d\u662f\u5148\u6267\u884c\/etc\/environment\uff0c\u540e\u6267\u884c\/etc\/profile\u5462\uff1f<br \/>\n\u8fd9\u662f\u56e0\u4e3a\uff1a \/etc\/environment\u662f\u8bbe\u7f6e\u6574\u4e2a\u7cfb\u7edf\u7684\u73af\u5883\uff0c\u800c\/etc\/profile\u662f\u8bbe\u7f6e\u6240\u6709\u7528\u6237\u7684\u73af\u5883\uff0c\u524d\u8005\u4e0e\u767b\u5f55\u7528\u6237\u65e0\u5173\uff0c\u540e\u8005\u4e0e\u767b\u5f55\u7528\u6237\u6709\u5173\u3002<\/p>\n<p>\u7cfb\u7edf\u5e94\u7528\u7a0b\u5e8f\u7684\u6267\u884c\u4e0e\u7528\u6237\u73af\u5883\u53ef\u4ee5\u662f\u65e0\u5173\u7684\uff0c\u4f46\u4e0e\u7cfb\u7edf\u73af\u5883\u662f\u76f8\u5173\u7684\uff0c\u6240\u4ee5\u5f53\u4f60\u767b\u5f55\u65f6\uff0c\u4f60\u770b\u5230\u7684\u63d0\u793a\u4fe1\u606f\uff0c\u5982\u65e5\u671f\u3001\u65f6\u95f4\u4fe1\u606f\u7684\u663e\u793a\u683c\u5f0f\u4e0e\u7cfb\u7edf\u73af\u5883\u7684LANG\u662f\u76f8\u5173\u7684\uff0c\u7f3a\u7701LANG=en_US\uff0c\u5982\u679c\u7cfb\u7edf\u73af\u5883LANG=zh_CN\uff0c\u5219\u63d0\u793a\u4fe1\u606f\u662f\u4e2d\u6587\u7684\uff0c\u5426\u5219\u662f\u82f1\u6587\u7684\u3002<\/p>\n<p>\u5bf9\u4e8e\u7528\u6237\u7684shell\u521d\u59cb\u5316\u800c\u8a00\u662f\u5148\u6267\u884c\/etc\/profile\uff0c\u518d\u8bfb\u53d6\u6587\u4ef6\/etc\/environment\uff1b\u5bf9\u6574\u4e2a\u7cfb\u7edf\u800c\u8a00\u662f\u5148\u6267\u884c\/etc\/environment\u3002\u8fd9\u6837\u7406\u89e3\u6b63\u786e\u5417\uff1f<br \/>\n\u767b\u9646\u7cfb\u7edf\u65f6\u7684\u987a\u5e8f\u5e94\u8be5\u662f<\/p>\n<p>\/etc\/enviroment &#8211;&gt; \/etc\/profile &#8211;&gt; $HOME\/.profile &#8211;&gt;$HOME\/.<span class=\"wp_keywordlink\"><a title=\"env\u547d\u4ee4\" href=\"https:\/\/man.linuxde.net\/env\" target=\"_blank\">env<\/a><\/span> (\u5982\u679c\u5b58\u5728)<br \/>\n\/etc\/profile \u662f\u6240\u6709\u7528\u6237\u7684\u73af\u5883\u53d8\u91cf<br \/>\n\/etc\/enviroment\u662f\u7cfb\u7edf\u7684\u73af\u5883\u53d8\u91cf<\/p>\n<p>\u767b\u9646\u7cfb\u7edf\u65f6shell\u8bfb\u53d6\u7684\u987a\u5e8f\u5e94\u8be5\u662f<br \/>\n\/etc\/profile -&gt;\/etc\/enviroment &#8211;&gt;$HOME\/.profile &#8211;&gt;$HOME\/.env<br \/>\n\u539f\u56e0\u5e94\u8be5\u662f\u7528\u6237\u73af\u5883\u548c\u7cfb\u7edf\u73af\u5883\u7684\u533a\u522b\u4e86\uff0c\u5982\u679c\u540c\u4e00\u4e2a\u53d8\u91cf\u5728\u7528\u6237\u73af\u5883(\/etc\/profile)\u548c\u7cfb\u7edf\u73af\u5883(\/etc\/environment)\u6709\u4e0d\u540c\u7684\u503c\uff0c\u90a3\u5e94\u8be5\u662f\u4ee5\u7528\u6237\u73af\u5883\u4e3a\u51c6<\/p>\n<\/div>\n<p>\u539f\u6587\u94fe\u63a5\uff1ahttps:\/\/www.linuxde.net\/2013\/10\/15352.html<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u767b\u5f55Linux\u65f6\u8981\u6267\u884c\u6587\u4ef6\u7684\u8fc7\u7a0b\u5982\u4e0b\uff1a \u5728\u521a\u767b\u5f55Linux\u65f6\uff0c\u9996\u5148\u542f\u52a8 \/etc\/profile \u6587\u4ef6\uff0c\u7136\u540e &#8230; <a title=\"Linux \u4e4b \/etc\/profile\u3001~\/.bash_profile \u7b49\u51e0\u4e2a\u6587\u4ef6\u7684\u6267\u884c\u8fc7\u7a0b\" class=\"read-more\" href=\"https:\/\/cn.hostease.com\/xueyuan\/jishu\/linux-%e4%b9%8b-etcprofile%e3%80%81-bash_profile-%e7%ad%89%e5%87%a0%e4%b8%aa%e6%96%87%e4%bb%b6%e7%9a%84%e6%89%a7%e8%a1%8c%e8%bf%87%e7%a8%8b\/\" aria-label=\"\u9605\u8bfb Linux \u4e4b \/etc\/profile\u3001~\/.bash_profile \u7b49\u51e0\u4e2a\u6587\u4ef6\u7684\u6267\u884c\u8fc7\u7a0b\">\u9605\u8bfb\u66f4\u591a<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[49,5],"tags":[529],"class_list":["post-1663","post","type-post","status-publish","format-standard","hentry","category-linux","category-jishu","tag-linuxetcprofile-bash_profile"],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/posts\/1663","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/comments?post=1663"}],"version-history":[{"count":1,"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/posts\/1663\/revisions"}],"predecessor-version":[{"id":1664,"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/posts\/1663\/revisions\/1664"}],"wp:attachment":[{"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/media?parent=1663"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/categories?post=1663"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/tags?post=1663"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}