{"id":7190,"date":"2024-04-12T12:01:01","date_gmt":"2024-04-12T04:01:01","guid":{"rendered":""},"modified":"2024-04-12T12:01:01","modified_gmt":"2024-04-12T04:01:01","slug":"linux\u4e91\u670d\u52a1\u7ec8\u7aef\u63d0\u793a\u7b26\u663e\u793a-bash-4.2#\u89e3\u51b3\u65b9\u6cd5","status":"publish","type":"post","link":"https:\/\/mushiming.com\/7190.html","title":{"rendered":"linux\u4e91\u670d\u52a1\u7ec8\u7aef\u63d0\u793a\u7b26\u663e\u793a-bash-4.2#\u89e3\u51b3\u65b9\u6cd5"},"content":{"rendered":"

\n <\/path> \n<\/svg> <\/p>\n

\u4eca\u5929\u8fde\u63a5\u5230\u4e91\u670d\u52a1\u5668\u7a81\u7136\u53d1\u73b0\u8f93\u5165\u547d\u4ee4\u65e0\u6548
\u51fa\u73b0\u8fd9\u79cd\u60c5\u51b5
\"linux\u4e91\u670d\u52a1\u7ec8\u7aef\u63d0\u793a\u7b26\u663e\u793a-bash-4.2#\u89e3\u51b3\u65b9\u6cd5
\u5c1d\u8bd5\u4f7f\u7528Ctrl+C \u9000\u51fa
\"linux\u4e91\u670d\u52a1\u7ec8\u7aef\u63d0\u793a\u7b26\u663e\u793a-bash-4.2#\u89e3\u51b3\u65b9\u6cd5
\u7ed3\u679c\u53d8\u6210-bash-4.2#
\u7f51\u4e0a\u67e5\u4e86\u534a\u5929 \u5f88\u591a\u4eba\u591a\u8bf4\u662f\u8bef\u5220\u4e86\u4e24\u4e2a\u6587\u4ef6
\u4f46\u6211\u67e5\u770b\u53d1\u73b0\u8fd9\u4e24\u4e2a\u6587\u4ef6\u90fd\u5b58\u5728
\u8f93\u5165\u547d\u4ee4\uff1a l. \u67e5\u770b\u6240\u6709\u9690\u85cf\u6587\u4ef6
\"linux\u4e91\u670d\u52a1\u7ec8\u7aef\u63d0\u793a\u7b26\u663e\u793a-bash-4.2#\u89e3\u51b3\u65b9\u6cd5
\u5982\u679c\u6ca1\u6709\u8fd9\u4e24\u4e2a\u9690\u85cf\u6587\u4ef6\u5c31\u4eceetc\u4e0b\u590d\u5236\u8fc7\u6765<\/p>\n

cp \/<\/span>etc\/<\/span>skel\/<\/span>.<\/span>bashrc \/<\/span>root\/<\/span>\ncp \/<\/span>etc\/<\/span>skel\/<\/span>.<\/span>bash_profile  \/<\/span>root\/<\/span>\n<\/code><\/pre>\n

\u7136\u800c\u6211\u7684\u8fd9\u4e24\u4e2a\u6587\u4ef6\u90fd\u5b58\u5728\uff0c\u8bf4\u660e\u4e0d\u662f\u8fd9\u4e2a\u95ee\u9898
\u7ec8\u4e8e\u7ffb\u4e86\u597d\u591a\u8d44\u6599\u53d1\u73b0
\u8fd9\u4e2a\u95ee\u9898\u51fa\u73b0\u7684\u539f\u56e0\u662f.bashrc\u6587\u4ef6\u88ab\u7834\u574f\uff0c\u5bfc\u81f4\u91cc\u9762\u6ca1\u6709\u8be5\u6709\u7684\u5185\u5bb9
\u4e8e\u662f\u7f16\u8f91.bashrc\u6587\u4ef6<\/p>\n

vim .<\/span>bashrc\n<\/code><\/pre>\n

\u5728\u6700\u540e\u4e00\u884c\u52a0\u5165<\/p>\n

PS1=<\/span>'[\\u@\\h \\W]$ '<\/span>>><\/span>.<\/span>bashrc\n<\/code><\/pre>\n

\"linux\u4e91\u670d\u52a1\u7ec8\u7aef\u63d0\u793a\u7b26\u663e\u793a-bash-4.2#\u89e3\u51b3\u65b9\u6cd5
\u7136\u540e \uff1awq \u4fdd\u5b58
\u5237\u65b0.bashrc\u6587\u4ef6<\/p>\n

source .<\/span>bashrc\n<\/code><\/pre>\n

\u8fd9\u6837\u5c31\u89e3\u51b3\u4e86
\"linux\u4e91\u670d\u52a1\u7ec8\u7aef\u63d0\u793a\u7b26\u663e\u793a-bash-4.2#\u89e3\u51b3\u65b9\u6cd5
\u4f46\u662f\u53d1\u73b0\u6bcf\u6b21\u6253\u5f00Xshell\u7ec8\u7aef\uff0c\u90fd\u8981source\u4e00\u4e0b.bashrc
\u518d\u7814\u7a76\u8fc7\u7a0b\u4e2d\u53d1\u73b0\u7b80\u4e66\u4e0a\u6709\u4e00\u7bc7\u6587\u7ae0\u89e3\u51b3\u4e86\u6b64\u95ee\u9898\uff1a
https:\/\/www.jianshu.com\/p\/35ad1b375e50<\/p>\n

\u56e0\u4e3aLinux\u542f\u52a8\u65f6\u8bfb\u53d6\u914d\u7f6e\u6587\u4ef6\u7684\u987a\u5e8f\u3002
\u5728\u521a\u767b\u5f55Linux\u65f6\uff0c\u9996\u5148\u542f\u52a8\/etc\/profile<\/code> \u6587\u4ef6\uff0c\u7136\u540e\u518d\u542f\u52a8\u7528\u6237\u76ee\u5f55\u4e0b\u7684 ~\/.bash_profile<\/code>\u3001~\/.bash_login<\/code>\u6216 ~\/.profile<\/code>\u6587\u4ef6\u4e2d\u7684\u5176\u4e2d\u4e00\u4e2a\uff0c
\u6267\u884c\u7684\u987a\u5e8f\u4e3a\uff1a~\/.bash_profile<\/code>\u3001~\/.bash_login<\/code>\u3001 ~\/.profile<\/code>\u3002<\/p>\n

\u5982\u679c ~\/.bash_profile<\/code>\u6587\u4ef6\u5b58\u5728\u7684\u8bdd\uff0c\u4e00\u822c\u8fd8\u4f1a\u6267\u884c ~\/.bashrc\u6587\u4ef6\u3002
\u56e0\u4e3a\u5728~\/.bash_profile<\/code>\u6587\u4ef6\u4e2d\u4e00\u822c\u4f1a\u6709\u4e0b\u9762\u7684\u4ee3\u7801\uff1a<\/p>\n

if<\/span> [<\/span> -<\/span>f ~<\/span>\/<\/span>.<\/span>bashrc ]<\/span> ;<\/span> then\n        source .<\/span>bashrc\nfi \n<\/code><\/pre>\n

~\/.bashrc<\/code>\u4e2d\uff0c\u4e00\u822c\u8fd8\u4f1a\u6709\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n

if<\/span> [<\/span> -<\/span>f \/<\/span>etc\/<\/span>bashrc ]<\/span> ;<\/span> then\n        source .<\/span>bashrc\nfi \n<\/code><\/pre>\n

\u6240\u4ee5\uff0c~\/.bashrc<\/code>\u4f1a\u8c03\u7528\/etc\/bashrc\u6587\u4ef6\u3002\u6700\u540e\uff0c\u5728\u9000\u51fashell\u65f6\uff0c\u8fd8\u4f1a\u6267\u884c ~\/.bash_logout<\/code>\u6587\u4ef6\u3002<\/p>\n

\u603b\u7ed3\u4e00\u4e0b\uff0c\u8fd9\u4e9b\u914d\u7f6e\u6587\u4ef6\u7684\u6267\u884c\u987a\u5e8f\u4e3a\uff1a\/etc\/profile<\/code>\u2192 (~\/.bash_profile<\/code> | ~\/.bash_login<\/code> | ~\/.profile<\/code>)\u2192~\/.bashrc<\/code> \u2192\/etc\/bashrc<\/code> \u2192 ~\/.bash_logout<\/code><\/p>\n

\u56e0\u4e3a\u5728~\/.bash_profile<\/code>\u6587\u4ef6\u4e2d\u6ca1\u6709\u4e0b\u9762\u7684\u4ee3\u7801\uff1a<\/p>\n

if<\/span> [<\/span> -<\/span>f ~<\/span>\/<\/span>.<\/span>bashrc ]<\/span> ;<\/span> then\n        source .<\/span>bashrc\nfi \n<\/code><\/pre>\n

\u6240\u4ee5linux\u5c31\u4e0d\u4f1a\u81ea\u52a8\u6267\u884c~\/.bashrc\u6587\u4ef6\uff0c\u6240\u4ee5\u4f60\u6bcf\u6b21\u767b\u9646\u7684\u65f6\u5019\u90fd\u8981\u624b\u52a8\u8f93\u5165source ~\/.bashrc<\/code>\u3002
\u89e3\u51b3\u65b9\u6cd5\uff1a<\/strong>
vim ~\/.bash_profile<\/code>\u5728\u6587\u4ef6\u5185\u90e8\u8f93\u5165<\/p>\n

   # \u52a0\u8f7d.<\/span>bashrc\u6587\u4ef6\nif<\/span> test -<\/span>f .<\/span>bashrc ;<\/span> then\nsource .<\/span>bashrc \nfi\n<\/code><\/pre>\n

\u8f93\u5165:wq<\/code>\u4fdd\u5b58\u5e76\u9000\u51fa\u5373\u53ef\u3002<\/p>\n

\u5173\u4e8e\u5404\u4e2a\u914d\u7f6e\u6587\u4ef6\u7684\u4f5c\u7528\u57df<\/strong>
\/etc\/profile<\/code>\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

\/etc\/bashrc<\/code>:
\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

~\/.bash_profile<\/code>:
\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

~\/.bashrc<\/code>:
\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

~\/.bash_logout<\/code>:
\u5f53\u6bcf\u6b21\u9000\u51fa\u7cfb\u7edf(\u9000\u51fabash shell)\u65f6,\u6267\u884c\u8be5\u6587\u4ef6. \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\"\u7236\u5b50\"\u5173\u7cfb\u3002<\/p>\n

~\/.bash_profile<\/code>: \u662f\u4ea4\u4e92\u5f0f\u3001login \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","protected":false},"excerpt":{"rendered":"linux\u4e91\u670d\u52a1\u7ec8\u7aef\u63d0\u793a\u7b26\u663e\u793a-bash-4.2#\u89e3\u51b3\u65b9\u6cd5\u4eca\u5929\u8fde\u63a5\u5230\u4e91\u670d\u52a1\u5668\u7a81\u7136\u53d1\u73b0\u8f93\u5165\u547d\u4ee4\u65e0\u6548\u51fa\u73b0\u8fd9\u79cd\u60c5\u51b5\u5c1d\u8bd5\u4f7f\u7528Ctrl+C\u9000\u51fa\u7ed3\u679c\u53d8...","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/7190"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=7190"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/7190\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=7190"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=7190"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=7190"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}