{"id":127,"date":"2023-08-14T17:12:56","date_gmt":"2023-08-14T09:12:56","guid":{"rendered":"http:\/\/8.130.131.184\/wordpress\/?p=127"},"modified":"2023-12-05T09:03:22","modified_gmt":"2023-12-05T01:03:22","slug":"shell-%e8%84%9a%e6%9c%ac%e7%bc%96%e7%a8%8b%e5%9f%ba%e7%a1%80","status":"publish","type":"post","link":"https:\/\/xianyijitan.top\/?p=127","title":{"rendered":"Shell \u811a\u672c\u7f16\u7a0b\u57fa\u7840"},"content":{"rendered":"<h2>Shell\u4ecb\u7ecd<\/h2>\n<ol>\n<li>\n<h3>\u4ec0\u4e48\u662fshell<\/h3>\n<p>Shell\u662f\u4e00\u4e2a\u547d\u4ee4\u89e3\u91ca\u5668\uff0c\u901a\u5e38\u6307\u7684\u662f\/bin\/bash\uff0c\u5b83\u5728\u64cd\u4f5c\u7cfb\u7edf\u7684\u6700\u5916\u5c42\u8d1f\u8d23\u76f4\u63a5\u4e0e\u7528\u6237\u5bf9\u8bdd\uff0c\u628a\u7528\u6237\u7684\u8f93\u5165\u89e3\u91ca\u7ed9\u64cd\u4f5c\u7cfb\u7edf\uff0c\u5e76\u4e14\u5904\u7406\u64cd\u4f5c\u7cfb\u7edf\u7684\u8f93\u51fa\u7ed3\u679c\uff0c\u8f93\u51fa\u5230\u5c4f\u5e55\u7ed9\u7528\u6237\u3002\u8fd9\u79cd\u5bf9\u8bdd\u65b9\u5f0f\u53ef\u4ee5\u662f\u4ea4\u4e92\u65b9\u5f0f\u6216\u8005\u975e\u4ea4\u4e92\u5f0f\uff08\u811a\u672c\uff09\u7684\u3002<\/p>\n<p><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/8.130.131.184\/wp-blog\/typora-user-images\/image-20230814091108855.png?w=960\" alt=\"image-20230814091108855\" \/><\/p>\n<p>\u53ef\u4ee5\u901a\u8fc7\/etc\/shells\u6587\u4ef6\u67e5\u770b\u5f53\u524d\u7cfb\u7edf\u6240\u652f\u6301\u7684Shell\u811a\u672c\u79cd\u7c7b\uff1a<\/p>\n<pre><code class=\"language-shell\">#\u67e5\u770bshell\u811a\u672c\u79cd\u7c7b\n[root@www ~]# cat \/etc\/shells\n\/bin\/sh\n\/bin\/bash\n\/usr\/bin\/sh\n\/usr\/bin\/bash\n\/usr\/bin\/tmux\n\/bin\/tmux\n\/usr\/bin\/zsh\n\/bin\/zsh<\/code><\/pre>\n<p>\u5207\u6362shell\u73af\u5883\u7684\u65b9\u6cd5<\/p>\n<pre><code class=\"language-shell\">#usermod\u547d\u4ee4\uff1a\nusermod -s \/bin\/bash \u7528\u6237\u540d\n#chsh\u547d\u4ee4\uff1a\nchsh -s \/bin\/bash \u7528\u6237\u540d\n#\u624b\u52a8\u5207\u6362\uff1a\n[root@www ~]# \/bin\/sh\nsh-4.4# exit\nexit\n[root@www ~]# sh\nsh-4.4# exit\nexit<\/code><\/pre>\n<\/li>\n<li>\n<h3>\u4ec0\u4e48\u662fShell\u811a\u672c<\/h3>\n<p>\u5f53Linux\u547d\u4ee4\u6216\u8005\u8bed\u53e5\u4e0d\u5728\u547d\u4ee4\u884c\u4e0b\u6267\u884c\uff0c\u800c\u662f\u901a\u8fc7\u4e00\u4e2a\u7a0b\u5e8f\u6587\u4ef6\u6267\u884c\u65f6\uff0c\u8be5\u7a0b\u5e8f\u5c31\u88ab\u79f0\u4e3ashell\u811a\u672c\u3002\u7528\u6237\u5728shell\u811a\u672c\u4e2d\u5199\u5165\u4e00\u7cfb\u5217\u7684\u547d\u4ee4\u8bed\u53e5\u7ec4\u5408\uff0c\u5e76\u4e14\u5c06\u8fd9\u4e9b\u547d\u4ee4\u3001\u53d8\u91cf\u548c\u6d41\u7a0b\u63a7\u5236\u8bed\u53e5\u6709\u673a\u7684\u7ec4\u5408\u5728\u4e00\u8d77\u5c31\u5f62\u6210\u4e86\u4e00\u4e2a\u529f\u80fd\u5f3a\u5927shell\u811a\u672c\u3002<\/li>\n<li>\n<h3>shell\u7684\u6267\u884c\u65b9\u5f0f<\/h3>\n<p>\u4ea4\u4e92\u5f0f\u6267\u884c\u7684\u547d\u4ee4\uff1a\u4eba\u5de5\u5e72\u9884\u3001\u667a\u80fd\u5316\u7a0b\u5ea6\u9ad8\u3001\u9010\u6761\u89e3\u91ca\u6267\u884c\u3001\u6548\u7387\u4f4e<\/p>\n<p>\u975e\u4ea4\u4e92\u6267\u884c\u7684\u811a\u672c\uff1a\u9700\u63d0\u524d\u8bbe\u7f6e\u3001\u667a\u80fd\u5316\u96be\u5ea6\u5927\u3001\u6279\u91cf\u6267\u884c\u3001\u6548\u7387\u9ad8\uff0c\u65b9\u4fbf\u5199\u811a\u672c\u540e\u53f0\u8fd0\u884c<\/li>\n<\/ol>\n<h2>Shell\u811a\u672c\u6267\u884c<\/h2>\n<ol>\n<li>\n<h3>Shell\u811a\u672c\u7684\u5efa\u7acb<\/h3>\n<p>\u5728Linux\u4e2dShell\u811a\u672c\u901a\u5e38\u662f\u5728\u7f16\u8f91\u5668\uff08vi\/vim\uff09\u4e2d\u7f16\u5199\u7684\uff0c\u811a\u672c\u7684\u7b2c\u4e00\u884c\u4f1a\u6307\u51fa\u7531\u54ea\u4e00\u4e2a\u89e3\u91ca\u5668\u6765\u6267\u884c\u811a\u672c\u4e2d\u7684\u5185\u5bb9\uff0c\u6bd4\u5982\uff1a<\/p>\n<pre><code class=\"language-shell\"># !\/bin\/bash\n# \u6ce8\u91ca\n\u53ef\u6267\u884c\u547d\u4ee4<\/code><\/pre>\n<p>\u811a\u672c\u4e2d\u5f00\u5934\u7684\"#!\"\u88ab\u79f0\u4e3a\u5e7b\u6570\uff0c\u5728\u6267\u884cbash\u811a\u672c\u65f6\uff0c\u5185\u6838\u4f1a\u6839\u636e\u201c#!\u201d\u540e\u7684\u89e3\u91ca\u5668\u6765\u786e\u5b9a\u4f7f\u7528\u4f55\u79cd\u89e3\u91ca\u5668\u6765\u89e3\u91ca\u811a\u672c\u7684\u5185\u5bb9\u3002<\/p>\n<p>\u8fd0\u884c\uff1a<\/p>\n<pre><code class=\"language-shell\">#\u7b2c\u4e00\u79cd\u65b9\u5f0f\uff1a\u6307\u5b9a\u811a\u672c\u6587\u4ef6\u7684\u8def\u5f84\uff0c\u524d\u63d0\u662f\u7531x\u6743\u9650\n[root@www ~]# vim first.sh\n#!\/bin\/bash\n#A test program for Shell-Script\n#\u4ec5\u4ec5\u7528\u4e8e\u8f93\u51fa\u6253\u5370 hello word\necho \"hello World! ^_^\"\n[root@www ~]# chmod +x first.sh\n[root@www ~]# \/root\/first.sh\nhello World! ^_^\n#\u7b2c\u4e8c\u79cd\u65b9\u5f0f\uff1assh \u811a\u672c\u6587\u4ef6\u8def\u5f84\n[root@www ~]# sh \/root\/first.sh \nhello World! ^_^\n#\u7b2c\u4e09\u79cd\u65b9\u5f0f\uff1asource \u811a\u672c\u6587\u4ef6\u8def\u5f84\n[root@www ~]# source \/root\/first.sh \nhello World! ^_^\n#\u7b2c\u56db\u79cd\u65b9\u5f0f\uff1a . \u811a\u672c\u6587\u4ef6\u8def\u5f84\n[root@www ~]# . \/root\/first.sh\nhello World! ^_^<\/code><\/pre>\n<p>\u8c03\u8bd5\uff1a<\/p>\n<pre><code class=\"language-shell\"># \u7b2c\u4e00\u79cd\u65b9\u5f0f\uff1a\u76f4\u63a5\u89c2\u5bdf\u6267\u884c\u4e2d\u7684\u8f93\u51fa\u3001\u62a5\u9519\u4fe1\u606f\n# \u7b2c\u4e8c\u79cd\u65b9\u5f0f\uff1a\u901a\u8fc7 sh -x \u5f00\u542f\u8c03\u8bd5\u6a21\u5f0f\n[root@www ~]# sh -x \/root\/first.sh \n+ echo 'hello World! ^_^'\nhello World! ^_^\n+ ls \/root\/\n\u516c\u5171  \u4e0b\u8f7d             anaconda_s      etc1.txt      haha.tar.xz           \n+ echo \u6267\u884c\u7ed3\u675f\n\u6267\u884c\u7ed3\u675f\n#\u7b2c\u4e09\u79cd\u65b9\u5f0f\uff1a \u901a\u8fc7 bash -x \u5f00\u542f\u8c03\u8bd5\u6a21\u5f0f\n[root@www ~]# bash -x first.sh \n+ echo 'hello World! ^_^'\nhello World! ^_^\n+ ls \/root\/root\nls: \u65e0\u6cd5\u8bbf\u95ee'\/root\/root': \u6ca1\u6709\u90a3\u4e2a\u6587\u4ef6\u6216\u76ee\u5f55\n+ echo \u6267\u884c\u7ed3\u675f\n\u6267\u884c\u7ed3\u675f\n#\u7b2c\u56db\u79cd\u65b9\u5f0f\uff1a \u5728\u53ef\u80fd\u51fa\u9519\u7684\u5730\u65b9\u8bbe\u7f6eecho<\/code><\/pre>\n<\/li>\n<li>\n<h3>shell\u53d8\u91cf<\/h3>\n<p><strong>\u53d8\u91cf\u7684\u8bbe\u7f6e\u4e0e\u53d6\u6d88<\/strong><\/p>\n<p>\u5b9a\u4e49\/\u8d4b\u503c\u53d8\u91cf<\/p>\n<ul>\n<li>\u53d8\u91cf\u540d=\u53d8\u91cf\u503c<\/li>\n<\/ul>\n<pre><code class=\"language-shell\">[root@www ~]# x=12\n[root@www ~]# var1=centos<\/code><\/pre>\n<p>\u200b \u6ce8\u610f\u4e8b\u9879\uff1a<\/p>\n<ol>\n<li>\u82e5\u6307\u5b9a\u7684\u53d8\u91cf\u540d\u5df2\u5b58\u5728\uff0c\u76f8\u5f53\u4e8e\u4e3a\u6b64\u53d8\u91cf\u91cd\u65b0\u8d4b\u503c<\/li>\n<li>\u7b49\u53f7\u4e24\u8fb9\u4e0d\u8981\u6709\u7a7a\u683c<\/li>\n<li>\u53d8\u91cf\u540d\u7531\u5b57\u6bcd\/\u6570\u5b57\/\u4e0b\u5212\u7ebf\u7ec4\u6210\uff0c\u533a\u5206\u5927\u5c0f\u5199<\/li>\n<li>\u53d8\u91cf\u540d\u4e0d\u96be\u4ee5\u6570\u5b57\u5f00\u5934\uff0c\u4e0d\u8981\u4f7f\u7528\u5173\u952e\u5b57\u548c\u7279\u6b8a\u5b57\u7b26(\u5982\uff1a+\u3001-\u3001\uff01\u7b49)<\/li>\n<\/ol>\n<ul>\n<li>\u67e5\u770b\u53d8\u91cf<\/li>\n<li>\u5f15\u7528\u53d8\u91cf\u503c\uff1a$\u53d8\u91cf\u540d<\/li>\n<li>\u67e5\u770b\u53d8\u91cf\u503c echo $\u53d8\u91cf\u540d \u3001echo ${\u53d8\u91cf\u540d}<\/li>\n<li>\n<pre><code class=\"language-shell\">[root@www ~]# echo $x\n12\n[root@www ~]# echo ${var1}\ncentos<\/code><\/pre>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<ul>\n<li>\u53d6\u6d88\u53d8\u91cf\n<ul>\n<li>unset \u53d8\u91cf\u540d<\/li>\n<li>\n<pre><code class=\"language-shell\">\n[root@www ~]# unset x\n[root@www ~]# echo $x<\/code><\/pre>\n<\/li>\n<\/ul>\n<p>[root@www ~]#<\/p>\n<pre><code><\/code><\/pre>\n<\/li>\n<\/ul>\n<h2>\u53d8\u91cf\u7684\u79cd\u7c7b<\/h2>\n<ul>\n<li>\n<h3>Shell\u53d8\u91cf\u5206\u7c7b<\/h3>\n<ul>\n<li>\u73af\u5883\u53d8\u91cf<\/li>\n<li>\u53d8\u91cf\u540d\u901a\u5e38\u5927\u5199\uff0c\u7531\u7cfb\u7edf\u7ef4\u62a4\uff0c\u7528\u6765\u8bbe\u7f6e\u5de5\u4f5c\u73af\u5883\uff0c\u53ea\u6709\u4e2a\u522b\u53d8\u91cf\u7528\u6237\u53ef\u4ee5\u76f4\u63a5\u4fee\u6539<\/li>\n<li>\u4f4d\u7f6e\u53d8\u91cf<\/li>\n<li>bash\u5185\u7f6e\u3002\u5b58\u50a8\u6267\u884c\u811a\u672c\u65f6\u63d0\u4f9b\u7684\u53c2\u6570<\/li>\n<li>\u9884\u5b9a\u4e49\u53d8\u91cf<\/li>\n<li>bash\u5185\u7f6e\u3002\u4e00\u7c7b\u6709\u7279\u6b8a\u7528\u9014\u7684\u53d8\u91cf\u3002\u53ef\u76f4\u63a5\u8c03\u7528\u3002\u4f46\u4e0d\u80fd\u76f4\u63a5\u8d4b\u503c\u4fee\u6539<\/li>\n<li>\u81ea\u5b9a\u4e49\u53d8\u91cf<\/li>\n<li>\u7531\u7528\u6237\u81ea\u4e3b\u8bbe\u7f6e\u3001\u4fee\u6539\u53ca\u4f7f\u7528<\/li>\n<\/ul>\n<\/li>\n<li>\n<h3>\u73af\u5883\u53d8\u91cf<\/h3>\n<ul>\n<li>\u914d\u7f6e\u6587\u4ef6\uff1a\/etc\/profile \u3001~\/.bash_profile<\/li>\n<li>\u76f8\u5173\u64cd\u4f5c<\/li>\n<li>env\uff1a\u5217\u51fa\u6240\u6709\u7684\u73af\u5883\u53d8\u91cf<\/li>\n<li>set\uff1a\u5217\u51fa\u6240\u6709\u53d8\u91cf<\/li>\n<li>\u5e38\u89c1\u7684\u73af\u5883\u53d8\u91cf<\/li>\n<li>PWD \uff1a\u5f53\u524d\u6240\u5728\u7684\u5de5\u4f5c\u76ee\u5f55<\/li>\n<li>PATH \uff1a\u547d\u4ee4\u641c\u7d22\u8def\u5f84<\/li>\n<li>.........<\/li>\n<\/ul>\n<\/li>\n<li>\n<h3>\u9884\u5b9a\u4e49\u53d8\u91cf<\/h3>\n<ul>\n<li>$0 \u5f53\u524d\u6240\u5728\u8fdb\u7a0b\u6216\u811a\u672c\u540d<\/li>\n<li>$$ \u5f53\u524d\u8fd0\u884c\u8fdb\u7a0b\u7684PID\u53f7<\/li>\n<li>$? \u547d\u4ee4\u6267\u884c\u540e\u7684\u8fd4\u56de\u72b6\u6001\uff0c0\u8868\u793a\u6b63\u5e38\uff0c1\u6216\u5176\u4ed6\u8868\u793a\u5f02\u5e38<\/li>\n<li>$# \u5df2\u52a0\u8f7d\u7684\u4f4d\u7f6e\u53d8\u91cf\u4e2a\u6570<\/li>\n<li>$* \u6240\u6709\u4f4d\u7f6e\u53d8\u91cf\u7684\u503c<\/li>\n<li>$@ \u6240\u6709\u4f4d\u7f6e\u53d8\u91cf\u7684\u503c<\/li>\n<\/ul>\n<\/li>\n<li>\n<h3>\u4f4d\u7f6e\u53d8\u91cf<\/h3>\n<ul>\n<li>\u5728\u6267\u884c\u811a\u672c\u65f6\u63d0\u4f9b\u7684\u547d\u4ee4\u884c\u53c2\u6570<\/li>\n<li>\u8868\u793a\u4e3a$n,n\u4e3a\u5e8f\u53f7<\/li>\n<li>$1\u3001$2\u3001.....${10}\u3001.......<\/li>\n<\/ul>\n<pre><code class=\"language-shell\">[root@www ~]# vim \/root\/test.sh\n#!\/bin\/bash\necho \"\u811a\u672c\u7684\u540d\u79f0\u4e3a\uff1a$0\"\necho \"\u7b2c\u4e00\u4e2a\u53c2\u6570\u7684\u540d\u79f0\u4e3a\uff1a$1\"\necho \"\u7b2c\u4e8c\u4e2a\u53c2\u6570\u7684\u540d\u79f0\u4e3a\uff1a$2\"\necho \"\u7b2c\u4e09\u4e2a\u53c2\u6570\u7684\u540d\u79f0\u4e3a\uff1a$3\"\necho \"\u7b2c\u56db\u4e2a\u53c2\u6570\u7684\u540d\u79f0\u4e3a\uff1a$4\"\necho \"\u7b2c\u4e94\u4e2a\u53c2\u6570\u7684\u540d\u79f0\u4e3a\uff1a$5\"\necho \"\u7b2c10\u4e2a\u53c2\u6570\u7684\u540d\u79f0\u4e3a\uff1a${10}\"\n[root@www ~]# chmod a+x test.sh \n[root@www ~]# \/root\/test.sh 1 2 3 4 5 6 7 8 9 10\n\u811a\u672c\u7684\u540d\u79f0\u4e3a\uff1a\/root\/test.sh\n\u7b2c\u4e00\u4e2a\u53c2\u6570\u7684\u540d\u79f0\u4e3a\uff1a1\n\u7b2c\u4e8c\u4e2a\u53c2\u6570\u7684\u540d\u79f0\u4e3a\uff1a2\n\u7b2c\u4e09\u4e2a\u53c2\u6570\u7684\u540d\u79f0\u4e3a\uff1a3\n\u7b2c\u56db\u4e2a\u53c2\u6570\u7684\u540d\u79f0\u4e3a\uff1a4\n\u7b2c\u4e94\u4e2a\u53c2\u6570\u7684\u540d\u79f0\u4e3a\uff1a5\n\u7b2c10\u4e2a\u53c2\u6570\u7684\u540d\u79f0\u4e3a\uff1a10<\/code><\/pre>\n<\/li>\n<\/ul>\n<h2>\u53d8\u91cf\u503c\u53ca\u8303\u56f4\u63a7\u5236<\/h2>\n<ul>\n<li>\n<h3>\u6269\u5c55\u8d4b\u503c\u64cd\u4f5c<\/h3>\n<pre><code class=\"language-shell\"># \u53cc\u5f15\u53f7\" \" :\u8fd0\u884c\u6269\u5c55\uff0c\u4ee5$\u5f15\u7528\u5176\u4ed6\u53d8\u91cf\n[root@www ~]# echo \"\u5475\u5475\u5475\uff0c\u4f60\u662f$USER\"\n\u5475\u5475\u5475\uff0c\u4f60\u662froot\n\n# \u5355\u5f15\u53f7' '  :\u7981\u6b62\u6269\u5c55\uff0c\u5373\u4f7f$\u4e5f\u89c6\u4e3a\u666e\u901a\u53d8\u91cf\n[root@www ~]# echo '\u5475\u5475\u5475\uff0c\u4f60\u662f$USER'\n\u5475\u5475\u5475\uff0c\u4f60\u662f$USER\u3001\n\n# \u53cd\u6487\u53f7<code>  <\/code> :\u5c06\u547d\u4ee4\u7684\u6267\u884c\u8f93\u51fa\u4f5c\u4e3a\u53d8\u91cf ;$()\u4e0e``\u7b49\u6548\uff0c\u4f46$()\u66f4\u65b9\u4fbf\u5d4c\u5957 [root@www yum.repos.d]# echo $a date [root@www yum.repos.d]# a=<code>date<\/code> [root@www yum.repos.d]# echo $a 2023\u5e74 08\u6708 14\u65e5 \u661f\u671f\u4e00 14:48:24 CST [root@www yum.repos.d]# a=$(date) [root@www yum.repos.d]# echo $a 2023\u5e74 08\u6708 14\u65e5 \u661f\u671f\u4e00 14:48:49 CST [root@www ~]# ls -l log-2023-08-14.tar.gz [root@www ~]# ls -l log-2023-08-14.tar.gz -rw-r--r-- 1 root root 1965203 8\u6708 14 14:50 log-2023-08-14.tar.gz<\/code><\/pre>\n<\/li>\n<li>\n<h3>read\u6807\u51c6\u8f93\u5165\u53d6\u503c<\/h3>\n<pre><code class=\"language-shell\"># \u683c\u5f0f\uff1a read [-p \"\u63d0\u793a\u4fe1\u606f\"] \u53d8\u91cf\u540d\n-p \u63d0\u793a\u4fe1\u606f\n[root@www ~]# read -p \"\u8bf7\u8f93\u5165\u4f60\u7684\u540d\u5b57\uff1a\" str\n\u8bf7\u8f93\u5165\u4f60\u7684\u540d\u5b57\uff1azhangsan\n[root@www ~]# echo $str\nzhangsan\n-t \u53ef\u6307\u5b9a\u8d85\u65f6\u79d2\u6570\n[root@www ~]# read -p \"\u8bf7\u8f93\u5165\u4f60\u7684\u540d\u5b57\uff1a\" -t 5 str\n\u8bf7\u8f93\u5165\u4f60\u7684\u540d\u5b57\uff1a\n[root@www ~]# echo $str\n\n[root@www ~]# \n\n# \u7ec8\u7aef\u663e\u793a\u63a7\u5236\uff1a\nstty -echo :\u5173\u95ed\u7ec8\u7aef\u8f93\u51fa(\u65e0\u663e\u793a)\nstty echo:\u6062\u590d\u7ec8\u7aef\u8f93\u51fa(\u663e\u793a)<\/code><\/pre>\n<\/li>\n<li>\n<h3>\u53d8\u91cf\u4f5c\u7528\u8303\u56f4<\/h3>\n<ul>\n<li>\u5c40\u90e8\u53d8\u91cf\uff1a\u53ea\u5728\u5f53\u524d\u7684shell\u73af\u5883\u6709\u6548\uff0c\u65e0\u6cd5\u5728\u5b50shell\u73af\u5883\u4e2d\u4f7f\u7528<\/li>\n<\/ul>\n<pre><code class=\"language-shell\">[root@www ~]# school=\"hello word!\"\n[root@www ~]# echo $school\nhello word!\n[root@www ~]# sh\nsh-4.4# echo $school\n\nsh-4.4# exit\nexit<\/code><\/pre>\n<ul>\n<li>\u5168\u5c40\u53d8\u91cf\uff1a\u5728\u5f53\u524dshell\u53ca\u5b50shell\u73af\u5883\u4e2d\u5747\u6709\u6548,\u4f7f\u7528export<\/li>\n<\/ul>\n<pre><code class=\"language-shell\"># export \u5c40\u90e8\u53d8\u91cf\u540d[=\u53d8\u91cf\u503c] ... ... \uff1a\u4e3a\u5c40\u90e8\u53d8\u91cf\u6dfb\u52a0\u5168\u5c40\u5c5e\u6027\n[root@www ~]# export school\n[root@www ~]# sh\nsh-4.4# echo $school\nhello word!\nsh-4.4# exit\nexit\n# export -n \u5168\u5c40\u53d8\u91cf\u540d... ...:\u53d6\u6d88\u6307\u5b9a\u53d8\u91cf\u7684\u5c5e\u6027<\/code><\/pre>\n<\/li>\n<\/ul>\n<h2>\u6570\u503c\u8fd0\u7b97<\/h2>\n<ul>\n<li>\n<h3>\u6574\u6570\u8fd0\u7b97<\/h3>\n<ul>\n<li>\u57fa\u672c\u8fd0\u7b97\u7c7b\u522b<\/li>\n<li>shell\u540c\u5176\u4ed6\u7f16\u7a0b\u8bed\u8a00\u4e00\u6837\uff0c\u652f\u6301\u591a\u79cd\u8fd0\u7b97\u7b26\uff0c\u5176\u4e2d\u7b97\u6570\u8fd0\u7b97\u7b26\uff1a+\u3001-\u3001*\u3001\/\u3001%\n<pre><code class=\"language-shell\"># \u52a0\u6cd5 +\n# \u51cf\u6cd5 -\n# \u4e58\u6cd5 *\n# \u9664\u6cd5 \/\n# \u6c42\u6a21 %<\/code><\/pre>\n<\/li>\n<li>expr \u8fd0\u7b97\u5de5\u5177<\/li>\n<\/ul>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: center;\">\u7c7b\u578b<\/th>\n<th style=\"text-align: center;\">\u8fd0\u7b97\u7b26<\/th>\n<th style=\"text-align: center;\">\u793a\u4f8b<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: center;\">\u52a0\u6cd5<\/td>\n<td style=\"text-align: center;\">+<\/td>\n<td style=\"text-align: center;\">expr 43 + 45\u3001expr $x + $y<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">\u51cf\u6cd5<\/td>\n<td style=\"text-align: center;\">-<\/td>\n<td style=\"text-align: center;\">expr 43 - 45\u3001expr $x - $y<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">\u4e58\u6cd5<\/td>\n<td style=\"text-align: center;\">*<\/td>\n<td style=\"text-align: center;\">expr 43 * 45\u3001expr $x * $y<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">\u9664\u6cd5<\/td>\n<td style=\"text-align: center;\">-\/<\/td>\n<td style=\"text-align: center;\">expr 43 \/ 45\u3001expr $x \/ $y<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">\u53d6\u4f59\u6570<\/td>\n<td style=\"text-align: center;\">-%<\/td>\n<td style=\"text-align: center;\">expr 43 % 45\u3001expr $x % $y<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u6ce8\u610f\uff1a\u8fd0\u7b97\u7b26\u4e0e\u53d8\u91cf\u4e4b\u95f4\u5fc5\u987b\u81f3\u5c11\u6709\u4e00\u4e2a\u7a7a\u683c\uff1b\u4e58\u6cd5\u64cd\u4f5c\u5e94\u91c7\u7528*\u8f6c\u4e49\uff0c\u907f\u514d\u88abshell\u89c6\u4e3a\u901a\u914d\u7b26<\/p>\n<ul>\n<li>$[]\u7b97\u5f0f\u66ff\u6362<\/li>\n<li>\u4f7f\u7528$[\u6574\u65701 \u8fd0\u7b97\u7b26 \u6574\u65702]<\/li>\n<li>\u4f7f\u7528$((\u6574\u65701 \u8fd0\u7b97\u7b26 \u6574\u65702))<\/li>\n<li>\u4e58\u6cd5\u64cd\u4f5c*\u65e0\u9700\u8f6c\u4e49<\/li>\n<li>\u5f15\u7528\u53d8\u91cf\u53ef\u7701\u7565$\u672c\u8eab<\/li>\n<\/ul>\n<pre><code class=\"language-shell\">[root@www ~]# x=45\n[root@www ~]# echo $[x+21]\n66\n[root@www ~]# echo $((x+21))\n66<\/code><\/pre>\n<ul>\n<li>\u53d8\u91cf\u7684\u81ea\u589e\u81ea\u51cf\u64cd\u4f5c<\/li>\n<li>\u53ef\u4f7f\u7528\u547d\u4ee4$[]\u6216let<\/li>\n<\/ul>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: center;\">\u7b80\u5199\u8868\u8fbe\u5f0f<\/th>\n<th style=\"text-align: center;\">\u5b8c\u6574\u8868\u8fbe\u5f0f<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: center;\">i++<\/td>\n<td style=\"text-align: center;\">i=i+1<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">i--<\/td>\n<td style=\"text-align: center;\">i=i-1<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">i+=2<\/td>\n<td style=\"text-align: center;\">i=i+2<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">i-=2<\/td>\n<td style=\"text-align: center;\">i=i-2<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">i*=2<\/td>\n<td style=\"text-align: center;\">i=i*2<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">i\/=2<\/td>\n<td style=\"text-align: center;\">i=i\/2<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">i%=2<\/td>\n<td style=\"text-align: center;\">i=i%2<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<pre><code class=\"language-shell\">[root@www ~]# i=1\n[root@www ~]# let i++\n[root@www ~]# echo $i\n2\n[root@www ~]# i=$[i+=1]\n[root@www ~]# echo $[i+=1]\n4<\/code><\/pre>\n<p>\u6ce8\u610f\uff1a++i \u4e0e i++ \u540c\u5176\u4ed6\u7f16\u7a0b\u8bed\u8a00\u4e00\u6837<\/li>\n<li>\n<h3>\u5c0f\u6570\u8fd0\u7b97<\/h3>\n<ul>\n<li>\u6574\u6570\u8fd0\u7b97\u7684\u5c40\u9650\u6027<\/li>\n<li>Bash\u5185\u4ec5\u652f\u6301\u6574\u6570\u8fd0\u7b97\uff0cexpr\u547d\u4ee4\u3001$[] \u7b97\u5f0f\u66ff\u6362\u4e0d\u652f\u6301\u6709\u5c0f\u6570\u8fd0\u7b97<\/li>\n<\/ul>\n<pre><code class=\"language-shell\">[root@www ~]# expr 45 + 12.3\nexpr: \u975e\u6574\u6570\u53c2\u6570<\/code><\/pre>\n<ul>\n<li>\u4f7f\u7528bc\u5b9e\u73b0\u5c0f\u6570\u8fd0\u7b97<\/li>\n<\/ul>\n<pre><code class=\"language-shell\">[root@www ~]# bc\nbc 1.07.1\nCopyright 1991-1994, 1997, 1998, 2000, 2004, 2006, 2008, 2012-2017 Free Software Foundation, Inc.\nThis is free software with ABSOLUTELY NO WARRANTY.\nFor details type `warranty'. \n1.2 + 2.3\n3.5\n100.23 - 45.23\n55.00\nquit\n\n# scale\u53d8\u91cf\u7528\u6765\u7ea6\u675f\u5c0f\u6570\u4f4d\uff0c\u8bbe\u7f6e\u683c\u5f0fscale=n\n[root@www ~]# bc\nbc 1.07.1\nCopyright 1991-1994, 1997, 1998, 2000, 2004, 2006, 2008, 2012-2017 Free Software Foundation, Inc.\nThis is free software with ABSOLUTELY NO WARRANTY.\nFor details type `warranty'. \nscale=4\n12.34 * 45.23\n558.1382\nquit\n\n[root@www ~]# A=12.34\n[root@www ~]# echo \"$A * 78.56\" | bc\n969.43\n\n[root@www ~]# echo \"scale=4;$A * 78.56;5\/3\" | bc\n969.4304\n1.6666\n\n[root@www ~]# result=$(echo \"$A * 78.56\" | bc)\n[root@www ~]# echo $result\n969.43\n[root@w<\/code><\/pre>\n<ul>\n<li>\u5c0f\u6570\u503c\u5f97\u6bd4\u8f83<\/li>\n<li>\u57fa\u672c\u7528\u6cd5\uff1aecho \"\u6570\u503c1 \u6bd4\u8f83\u7b26 \u6570\u503c2\" | bc<\/li>\n<li>\u5982\u679c\u8868\u8fbe\u5f0f\u6210\u7acb\u3002\u5219\u8fd4\u56de\u7ed3\u679c\u4e3a1\uff0c\u5426\u5219\u8fd4\u56de0<\/li>\n<li>\u5e38\u89c1\u64cd\u4f5c\uff1a&gt;\u3001&gt;=\u3001&lt;\u3001&lt;=\u3001==\u3001!=<\/li>\n<\/ul>\n<pre><code class=\"language-shell\">[root@www ~]# a=12.35\n[root@www ~]# b=45.2\n[root@www ~]# echo \"$a == $b\" | bc\n0\n[root@www ~]# echo \"$a &gt; $b\" | bc\n0\n[root@www ~]# echo \"$a &lt; $b\" | bc\n1<\/code><\/pre>\n<\/li>\n<\/ul>\n<h2>\u6761\u4ef6\u6d4b\u8bd5<\/h2>\n<ul>\n<li>\n<h3>\u6d4b\u8bd5\u64cd\u4f5c\u6982\u8ff0<\/h3>\n<ul>\n<li>Shell\u811a\u672c\u7684\u667a\u80fd\u5316<\/li>\n<li>\u4e3a\u547d\u4ee4\u7684\u6267\u884c\u63d0\u4f9b\u6700\u76f4\u63a5\u7684\u8bc6\u522b\u4f9d\u636e<\/li>\n<li>\u6587\u4ef6\u6216\u76ee\u5f55\u7684\u8bfb\u3001\u5199\u7b49\u72b6\u6001<\/li>\n<li>\u6570\u503c\u5927\u5c0f<\/li>\n<li>\u5b57\u7b26\u4e32\u662f\u5426\u5339\u914d<\/li>\n<li>\u591a\u6761\u4ef6\u7ec4\u5408<\/li>\n<li>test\u6d4b\u8bd5\u64cd\u4f5c<\/li>\n<li>test \u9009\u9879 \u53c2\u6570<\/li>\n<li>[ \u9009\u9879 \u53c2\u6570 ] \u6ce8\u610f\uff1a[ ] \u4e0e\u6761\u4ef6\u8868\u8fbe\u5f0f\u4e4b\u95f4\u9700\u8981\u81f3\u5c11\u4e00\u4e2a\u7a7a\u683c\u8fdb\u884c\u5206\u9694<\/li>\n<\/ul>\n<\/li>\n<li>\n<h3>\u5e38\u89c1\u7684\u64cd\u4f5c\u6d4b\u8bd5<\/h3>\n<ul>\n<li>\u5b57\u7b26\u4e32\u6bd4\u8f83<\/li>\n<li>\u4e3b\u8981\u7528\u6cd5\uff1a[ \u64cd\u4f5c\u7b26 \u5b57\u7b26\u4e32 ] \u6216 [ \u5b57\u7b26\u4e321 \u64cd\u4f5c\u7b26 \u5b57\u7b26\u4e322 ]<\/li>\n<\/ul>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: center;\">\u64cd\u4f5c\u7b26<\/th>\n<th style=\"text-align: center;\">\u542b\u4e49<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: center;\">-z<\/td>\n<td style=\"text-align: center;\">\u5b57\u7b26\u4e32\u7684\u503c\u4e3a\u7a7a<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">-n<\/td>\n<td style=\"text-align: center;\">\u5b57\u7b26\u4e32\u7684\u503c\u4e0d\u4e3a\u7a7a<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">==<\/td>\n<td style=\"text-align: center;\">\u4e24\u4e2a\u5b57\u7b26\u4e32\u76f8\u540c<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">!=<\/td>\n<td style=\"text-align: center;\">\u4e24\u4e2a\u5b57\u7b26\u4e32\u4e0d\u540c<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<pre><code class=\"language-shell\"># \u793a\u4f8b\uff1a\n[root@www ~]# str=''\n[root@www ~]# [ -z $str ]\n[root@www ~]# echo $?\n0\n[root@www ~]# str='abc'\n[root@www ~]# [ -z $str ]\n[root@www ~]# echo $?\n1\n[root@www ~]# [ -n $str ]\n[root@www ~]# echo $?\n0\n[root@www ~]# str1='abc'\n[root@www ~]# str2='abc'\n[root@www ~]# [ $str1 == $str2 ]\n[root@www ~]# echo $?\n0\n[root@www ~]# [ $str1 != $str2 ]\n[root@www ~]# echo $?\n1<\/code><\/pre>\n<ul>\n<li>\u6574\u6570\u503c\u6bd4\u8f83<\/li>\n<li>\u4e3b\u8981\u7528\u6cd5\uff1a[ \u6574\u6570\u503c1 \u64cd\u4f5c\u7b26 \u6574\u6570\u503c2 ]<\/li>\n<\/ul>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: center;\">\u64cd\u4f5c\u7b26<\/th>\n<th style=\"text-align: center;\">\u542b\u4e49<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: center;\">-eq<\/td>\n<td style=\"text-align: center;\">\u7b49\u4e8e<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">-ne<\/td>\n<td style=\"text-align: center;\">\u4e0d\u7b49\u4e8e<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">-ge<\/td>\n<td style=\"text-align: center;\">\u5927\u4e8e\u6216\u7b49\u4e8e<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">-le<\/td>\n<td style=\"text-align: center;\">\u5c0f\u4e8e\u6216\u7b49\u4e8e<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">-gt<\/td>\n<td style=\"text-align: center;\">\u5927\u4e8e<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">-lt<\/td>\n<td style=\"text-align: center;\">\u5c0f\u4e8e<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<pre><code class=\"language-shell\">[root@www ~]# who\nroot     pts\/0        2023-08-14 14:43 (192.168.199.1)\nroot     pts\/1        2023-08-14 10:11 (192.168.199.1)\n[root@www ~]# who | wc -l\n2\n[root@www ~]# num=$(who | wc -l)\n[root@www ~]# [ $num -le 5 ] &amp;&amp; echo \"OK\"\nOK\n[root@www ~]# [ $(who | wc -l) -le 5 ] &amp;&amp; echo \"OK\"\nOK<\/code><\/pre>\n<ul>\n<li>\u6587\u4ef6\u72b6\u6001\u6d4b\u8bd5<\/li>\n<li>\u4e3b\u8981\u7528\u6cd5\uff1a[ \u64cd\u4f5c\u7b26 \u6587\u4ef6\u6216\u76ee\u5f55 ]<\/li>\n<\/ul>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: center;\">\u64cd\u4f5c\u7b26<\/th>\n<th style=\"text-align: center;\">\u542b\u4e49<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: center;\">-e<\/td>\n<td style=\"text-align: center;\">\u5224\u65ad\u5bf9\u8c61\u662f\u5426\u5b58\u5728\uff0c\u82e5\u5b58\u5728\u5219\u4e3a\u771f<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">-d<\/td>\n<td style=\"text-align: center;\">\u5224\u65ad\u5bf9\u8c61\u662f\u5426\u4e3a\u76ee\u5f55\uff0c\u82e5\u662f\u5219\u4e3a\u771f<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">-f<\/td>\n<td style=\"text-align: center;\">\u5224\u65ad\u5bf9\u8c61\u662f\u5426\u4e3a\u4e00\u822c\u6587\u4ef6\uff0c\u82e5\u662f\u5219\u4e3a\u771f<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">-r<\/td>\n<td style=\"text-align: center;\">\u5224\u65ad\u5bf9\u8c61\u662f\u5426\u6709\u53ef\u8bfb\u6743\u9650\uff0c\u82e5\u6709\u5219\u4e3a\u771f<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">-w<\/td>\n<td style=\"text-align: center;\">\u5224\u65ad\u5bf9\u8c61\u662f\u5426\u6709\u53ef\u5199\u6743\u9650\uff0c\u82e5\u6709\u5219\u4e3a\u771f<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">-x<\/td>\n<td style=\"text-align: center;\">\u5224\u65ad\u5bf9\u8c61\u662f\u5426\u6709\u53ef\u6267\u884c\u6743\u9650\uff0c\u82e5\u6709\u5219\u4e3a\u771f<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<pre><code class=\"language-shell\">[root@www ~]# [ -d \/etc\/hosts ]\n[root@www ~]# echo $?\n1\n[root@www ~]# [ -f \/etc\/hosts ]\n[root@www ~]# echo $?\n0\n[root@www ~]# [ -r \/etc\/hosts ]\n[root@www ~]# echo $?\n0\n[root@www ~]# [ -w \/etc\/hosts ]\n[root@www ~]# echo $?\n0\n[root@www ~]# [ -w \/etc\/hosts ] &amp;&amp; echo \"YES\"\nYES<\/code><\/pre>\n<\/li>\n<li>\n<h3>\u7ec4\u5408\u591a\u4e2a\u6761\u4ef6<\/h3>\n<ul>\n<li>\u903b\u8f91\u5206\u9694\u64cd\u4f5c<\/li>\n<li>\u4e3b\u8981\u7528\u6cd5\uff1a\u547d\u4ee41 \u64cd\u4f5c\u7b26 \u547d\u4ee42.......<\/li>\n<li>[ \u6761\u4ef61 ] \u64cd\u4f5c\u7b26 [ \u6761\u4ef62 ]<\/li>\n<\/ul>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: center;\">\u64cd\u4f5c\u7b26<\/th>\n<th style=\"text-align: center;\">\u542b\u4e49<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: center;\">&amp;&amp;<\/td>\n<td style=\"text-align: center;\">\u7ed9\u5b9a\u7684\u6761\u4ef6\u90fd\u5fc5\u987b\u6210\u7acb\uff0c\u6574\u4e2a\u7ed3\u679c\u4e3a\u771f<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">||<\/td>\n<td style=\"text-align: center;\">\u53ea\u8981\u5176\u4e2d\u4e00\u4e2a\u6761\u4ef6\u4e3a\u771f\uff0c\u5219\u7ed3\u679c\u4e3a\u771f<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<ul>\n<li>\u6761\u4ef6\u7ec4\u5408\u5e94\u7528<\/li>\n<\/ul>\n<pre><code class=\"language-shell\">[root@www ~]# [ $USER == \"root\" ] &amp;&amp; [ $PWD == \"\/root\" ]\n[root@www ~]# [ $? -eq 0 ] &amp;&amp; echo \"YES\"\nYES\n\n[root@www ~]# [ -d \"\/opt\/testdir\" ] || mkdir -p \/opt\/testdir\n[root@www ~]# ls -ld \/opt\/testdir\/\ndrwxr-xr-x 2 root root 6 8\u6708  14 16:57 \/opt\/testdir\/<\/code><\/pre>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Shell\u4ecb\u7ecd \u4ec0\u4e48\u662fshell Shell\u662f\u4e00\u4e2a\u547d\u4ee4\u89e3\u91ca\u5668\uff0c\u901a\u5e38\u6307\u7684\u662f\/bin\/bash\uff0c\u5b83\u5728\u64cd\u4f5c\u7cfb\u7edf\u7684\u6700\u5916\u5c42\u8d1f\u8d23\u76f4\u63a5\u4e0e\u7528\u6237\u5bf9\u8bdd\uff0c\u628a\u7528\u6237\u7684\u8f93\u5165\u89e3\u91ca\u7ed9\u64cd\u4f5c\u7cfb\u7edf\uff0c\u5e76\u4e14\u5904\u7406\u64cd\u4f5c\u7cfb\u7edf\u7684\u8f93\u51fa\u7ed3\u679c\uff0c\u8f93\u51fa\u5230\u5c4f\u5e55\u7ed9\u7528\u6237\u3002\u8fd9\u79cd\u5bf9\u8bdd\u65b9\u5f0f\u53ef\u4ee5\u662f\u4ea4\u4e92\u65b9\u5f0f\u6216\u8005\u975e\u4ea4\u4e92\u5f0f\uff08\u811a\u672c\uff09\u7684\u3002 \u53ef\u4ee5\u901a\u8fc7\/etc\/shells\u6587\u4ef6\u67e5\u770b\u5f53\u524d\u7cfb\u7edf\u6240\u652f\u6301\u7684Shell\u811a\u672c\u79cd\u7c7b\uff1a #\u67e5\u770bshell\u811a\u672c\u79cd\u7c7b [root@www ~]# cat \/etc\/shells \/bin\/sh \/bin\/bash \/usr\/bin\/sh \/usr\/bin\/bash \/usr\/bin\/tmux \/bin\/tmux \/usr\/bin\/zsh \/bin\/zsh \u5207\u6362shell\u73af\u5883\u7684\u65b9\u6cd5 #usermod\u547d\u4ee4\uff1a usermod -s \/bin\/bash \u7528\u6237\u540d #chsh\u547d\u4ee4\uff1a chsh -s \/bin\/bash \u7528\u6237\u540d #\u624b\u52a8\u5207\u6362\uff1a [root@www ~]# \/bin\/sh sh-4.4# exit exit [root@www ~]# sh sh-4.4# exit exit \u4ec0\u4e48\u662fShell\u811a\u672c \u5f53Linux\u547d\u4ee4\u6216\u8005\u8bed\u53e5\u4e0d\u5728\u547d\u4ee4\u884c\u4e0b\u6267\u884c\uff0c\u800c\u662f\u901a\u8fc7\u4e00\u4e2a\u7a0b\u5e8f\u6587\u4ef6\u6267\u884c\u65f6\uff0c\u8be5\u7a0b\u5e8f\u5c31\u88ab\u79f0\u4e3ashell\u811a\u672c\u3002\u7528\u6237\u5728shell\u811a\u672c\u4e2d\u5199\u5165\u4e00\u7cfb\u5217\u7684\u547d\u4ee4\u8bed\u53e5\u7ec4\u5408\uff0c\u5e76\u4e14\u5c06\u8fd9\u4e9b\u547d\u4ee4\u3001\u53d8\u91cf\u548c\u6d41\u7a0b\u63a7\u5236\u8bed\u53e5\u6709\u673a\u7684\u7ec4\u5408\u5728\u4e00\u8d77\u5c31\u5f62\u6210\u4e86\u4e00\u4e2a\u529f\u80fd\u5f3a\u5927shell\u811a\u672c\u3002 shell\u7684\u6267\u884c\u65b9\u5f0f \u4ea4\u4e92\u5f0f\u6267\u884c\u7684\u547d\u4ee4\uff1a\u4eba\u5de5\u5e72\u9884\u3001\u667a\u80fd\u5316\u7a0b\u5ea6\u9ad8\u3001\u9010\u6761\u89e3\u91ca\u6267\u884c\u3001\u6548\u7387\u4f4e \u975e\u4ea4\u4e92\u6267\u884c\u7684\u811a\u672c\uff1a\u9700\u63d0\u524d\u8bbe\u7f6e\u3001\u667a\u80fd\u5316\u96be\u5ea6\u5927\u3001\u6279\u91cf\u6267\u884c\u3001\u6548\u7387\u9ad8\uff0c\u65b9\u4fbf\u5199\u811a\u672c\u540e\u53f0\u8fd0\u884c Shell\u811a\u672c\u6267\u884c Shell\u811a\u672c\u7684\u5efa\u7acb \u5728Linux\u4e2dShell\u811a\u672c\u901a\u5e38\u662f\u5728\u7f16\u8f91\u5668\uff08vi\/vim\uff09\u4e2d\u7f16\u5199\u7684\uff0c\u811a\u672c\u7684\u7b2c\u4e00\u884c\u4f1a\u6307\u51fa\u7531\u54ea\u4e00\u4e2a\u89e3\u91ca\u5668\u6765\u6267\u884c\u811a\u672c\u4e2d\u7684\u5185\u5bb9\uff0c\u6bd4\u5982\uff1a # !\/bin\/bash # \u6ce8\u91ca \u53ef\u6267\u884c\u547d\u4ee4 \u811a\u672c\u4e2d\u5f00\u5934\u7684&#8221;#!&#8221;\u88ab\u79f0\u4e3a\u5e7b\u6570\uff0c\u5728\u6267\u884cbash\u811a\u672c\u65f6\uff0c\u5185\u6838\u4f1a\u6839\u636e\u201c#!\u201d\u540e\u7684\u89e3\u91ca\u5668\u6765\u786e\u5b9a\u4f7f\u7528\u4f55\u79cd\u89e3\u91ca\u5668\u6765\u89e3\u91ca\u811a\u672c\u7684\u5185\u5bb9\u3002 \u8fd0\u884c\uff1a #\u7b2c\u4e00\u79cd\u65b9\u5f0f\uff1a\u6307\u5b9a\u811a\u672c\u6587\u4ef6\u7684\u8def\u5f84\uff0c\u524d\u63d0\u662f\u7531x\u6743\u9650 [root@www ~]# vim first.sh #!\/bin\/bash #A test program for Shell-Script #\u4ec5\u4ec5\u7528\u4e8e\u8f93\u51fa\u6253\u5370 hello word echo &#8220;hello World! ^_^&#8221; [root@www ~]# chmod +x first.sh [root@www ~]# \/root\/first.sh hello World! ^_^ #\u7b2c\u4e8c\u79cd\u65b9\u5f0f\uff1assh \u811a\u672c\u6587\u4ef6\u8def\u5f84 [root@www ~]# sh \/root\/first.sh hello World! ^_^ #\u7b2c\u4e09\u79cd\u65b9\u5f0f\uff1asource \u811a\u672c\u6587\u4ef6\u8def\u5f84 [root@www ~]# source \/root\/first.sh hello World! ^_^ #\u7b2c\u56db\u79cd\u65b9\u5f0f\uff1a . \u811a\u672c\u6587\u4ef6\u8def\u5f84 [root@www ~]# . \/root\/first.sh hello World! ^_^ \u8c03\u8bd5\uff1a # \u7b2c\u4e00\u79cd\u65b9\u5f0f\uff1a\u76f4\u63a5\u89c2\u5bdf\u6267\u884c\u4e2d\u7684\u8f93\u51fa\u3001\u62a5\u9519\u4fe1\u606f # \u7b2c\u4e8c\u79cd\u65b9\u5f0f\uff1a\u901a\u8fc7 sh -x \u5f00\u542f\u8c03\u8bd5\u6a21\u5f0f [root@www ~]# sh -x \/root\/first.sh + echo &#8216;hello World! ^_^&#8217; hello World! ^_^ + ls \/root\/ \u516c\u5171 \u4e0b\u8f7d anaconda_s etc1.txt haha.tar.xz + echo \u6267\u884c\u7ed3\u675f \u6267\u884c\u7ed3\u675f #\u7b2c\u4e09\u79cd\u65b9\u5f0f\uff1a \u901a\u8fc7 bash -x \u5f00\u542f\u8c03\u8bd5\u6a21\u5f0f [root@www ~]# bash -x first.sh + echo &#8216;hello World! ^_^&#8217; hello World! ^_^ + ls \/root\/root ls: \u65e0\u6cd5\u8bbf\u95ee&#8217;\/root\/root&#8217;: \u6ca1\u6709\u90a3\u4e2a\u6587\u4ef6\u6216\u76ee\u5f55 + echo \u6267\u884c\u7ed3\u675f \u6267\u884c\u7ed3\u675f #\u7b2c\u56db\u79cd\u65b9\u5f0f\uff1a \u5728\u53ef\u80fd\u51fa\u9519\u7684\u5730\u65b9\u8bbe\u7f6eecho shell\u53d8\u91cf \u53d8\u91cf\u7684\u8bbe\u7f6e\u4e0e\u53d6\u6d88 \u5b9a\u4e49\/\u8d4b\u503c\u53d8\u91cf \u53d8\u91cf\u540d=\u53d8\u91cf\u503c [root@www ~]# x=12 [root@www ~]# var1=centos \u200b \u6ce8\u610f\u4e8b\u9879\uff1a \u82e5\u6307\u5b9a\u7684\u53d8\u91cf\u540d\u5df2\u5b58\u5728\uff0c\u76f8\u5f53\u4e8e\u4e3a\u6b64\u53d8\u91cf\u91cd\u65b0\u8d4b\u503c \u7b49\u53f7\u4e24\u8fb9\u4e0d\u8981\u6709\u7a7a\u683c \u53d8\u91cf\u540d\u7531\u5b57\u6bcd\/\u6570\u5b57\/\u4e0b\u5212\u7ebf\u7ec4\u6210\uff0c\u533a\u5206\u5927\u5c0f\u5199 \u53d8\u91cf\u540d\u4e0d\u96be\u4ee5\u6570\u5b57\u5f00\u5934\uff0c\u4e0d\u8981\u4f7f\u7528\u5173\u952e\u5b57\u548c\u7279\u6b8a\u5b57\u7b26(\u5982\uff1a+\u3001-\u3001\uff01\u7b49) \u67e5\u770b\u53d8\u91cf \u5f15\u7528\u53d8\u91cf\u503c\uff1a$\u53d8\u91cf\u540d \u67e5\u770b\u53d8\u91cf\u503c echo $\u53d8\u91cf\u540d \u3001echo ${\u53d8\u91cf\u540d} [root@www ~]# echo $x 12 [root@www ~]# echo ${var1} centos \u53d6\u6d88\u53d8\u91cf unset \u53d8\u91cf\u540d [root@www ~]# unset x [root@www ~]# echo $x [&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[6],"tags":[],"class_list":["post-127","post","type-post","status-publish","format-standard","hentry","category-lixx"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/xianyijitan.top\/index.php?rest_route=\/wp\/v2\/posts\/127","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/xianyijitan.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xianyijitan.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xianyijitan.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xianyijitan.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=127"}],"version-history":[{"count":3,"href":"https:\/\/xianyijitan.top\/index.php?rest_route=\/wp\/v2\/posts\/127\/revisions"}],"predecessor-version":[{"id":347,"href":"https:\/\/xianyijitan.top\/index.php?rest_route=\/wp\/v2\/posts\/127\/revisions\/347"}],"wp:attachment":[{"href":"https:\/\/xianyijitan.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=127"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xianyijitan.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=127"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xianyijitan.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=127"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}