{"id":233,"date":"2021-07-28T13:13:11","date_gmt":"2021-07-28T05:13:11","guid":{"rendered":"http:\/\/egonlin.com\/?p=233"},"modified":"2024-03-25T10:36:46","modified_gmt":"2024-03-25T02:36:46","slug":"bash-shell%e5%85%a5%e9%97%a8","status":"publish","type":"post","link":"https:\/\/egonlin.com\/?p=233","title":{"rendered":"Bash shell\u5165\u95e8"},"content":{"rendered":"<h1>Bash shell\u57fa\u7840<\/h1>\n<h2>\u4e00 \u4ecb\u7ecd<\/h2>\n<p>\u7c7b\u6bd4\uff1a<\/p>\n<ul>\n<li>\n<p>shell\u8bed\u6cd5\u300a==============\u300bpython\u8bed\u6cd5<\/p>\n<\/li>\n<li>\n<p>bash\u89e3\u91ca\u5668\u300a============\u300bpython\u89e3\u91ca\u5668<\/p>\n<\/li>\n<li>\n<p>\u5e73\u53f0 \u300a=================\u300b\u5e73\u53f0<\/p>\n<\/li>\n<\/ul>\n<p>shell\u662f\u4e00\u95e8\u89e3\u91ca\u578b\u3001\u5f31\u7c7b\u578b\u3001\u52a8\u6001\u8bed\u8a00<\/p>\n<h2>\u4e8c\u3001\u4ea4\u4e92\u5f0f\u4e0e\u975e\u4ea4\u4e92\u5f0f\uff08\u63a5\u6536\u6307\u4ee4\u5f62\u5f0f\u7684\u4e0d\u540c\uff09<\/h2>\n<p>shell\u73af\u5883\u63a5\u6536\u6307\u4ee4\u7684\u65b9\u5f0f\u4e0e\u4e24\u79cd\uff1a<br \/>\n1\u3001\u4ea4\u4e92\u5f0f\uff1a<br \/>\n\uff081\uff09\u6bcf\u6b21\u63a5\u6536\u7684\u662f\u5355\u72ec\u4e00\u6761\u547d\u4ee4<br \/>\n\uff082\uff09\u4ea4\u4e92\u7684\u542b\u4e49\u662f\u4f60\u7ed9\u5b83\u4e00\u6761\u6307\u4ee4\u5b83\u7acb\u5373\u7ed9\u4f60\u8fd4\u56de\u7ed3\u679c<\/p>\n<pre><code>\u5b83\u5c31\u597d\u6bd4\u662f\u4f60\u53bb\u8def\u8fb9\u644a\u5403\u5927\u9910:\n    \u8001\u677f\u95ee\uff1a\u5403\u4ec0\u4e48\n    \u4f60\uff1a\u5403\u84b8\u7f8a\u7f94\u3001\u84b8\u9e7f\u8338\u3001\u84b8\u718a\u638c\n    \u8001\u677f\u95ee\uff1a\u600e\u4e48\u4e2a\u505a\u6cd5\n    \u4f60\uff1a\u7f8a\u7f94\u70e4\u4e03\u5206\u719f\u3001\u9e7f\u8338\u6e05\u84b8\u3001\u718a\u638c\u7ea2\u70e7\n    \u8001\u677f\u95ee\uff1a\u52a0\u4e0d\u52a0\u9999\u83dc\n    \u4f60\uff1a\u591a\u52a0\u70b9\u9999\u83dc<\/code><\/pre>\n<p>2\u3001\u975e\u4ea4\u4e92\u5f0f\uff1a<br \/>\n\uff081\uff09\u6bcf\u6b21\u63a5\u6536\u7684\u4e00\u4e2a\u6587\u4ef6\uff0c\u6587\u4ef6\u91cc\u653e\u7f6e\u4e86\u5f88\u591a\u6761\u547d\u4ee4\uff0c\u8fd0\u884c\u65f6shell\u4f1a\u81ea\u4e0a\u800c\u4e0b\u4f9d\u6b21\u8fd0\u884c<br \/>\n\uff082\uff09\u975e\u4ea4\u4e92\u5f0f\u7684\u542b\u4e49\u662f\uff0c\u5c06\u5b9e\u73b0\u67d0\u4e00\u9700\u6c42\u7684\u4e00\u7cfb\u5217\u6307\u4ee4\u5806\u780c\u5230\u4e00\u8d77\uff0c\u6254\u5230\u4e00\u4e2a\u6587\u4ef6\u4e2d\uff0c\u5f62\u6210\u4e00\u4e2a\u7b80\u5355\u7684\u7a0b\u5e8f\u7136\u540e\u4ea4\u7ed9shell\u6267\u884c\uff0c<\/p>\n<pre><code>\u8fd8\u662f\u53bb\u8def\u8fb9\u644a\u5403\u5927\u9910\u7684\u4f8b\u5b50\n    1\u3001\u4f60\u4e8b\u5148\u5c06\u5c06\u5b9e\u73b0\u4f60\u9700\u6c42\u7684\u6307\u4ee4\u90fd\u5199\u5230\u4e86\u4e00\u4e2a\u6587\u4ef6\u4e2d\n    \u98df\u6750\uff1a\u7f8a\u7f94\u3001\u9e7f\u8338\u3001\u718a\u638c\n    \u70e4\u7f8a\u7f94\n    \u6e05\u84b8\u9e7f\u8338\n    \u7ea2\u70e7\u718a\u7ad9\n    \u591a\u52a0\u9999\u83dc\n\n    2\u3001\u7136\u540e\u4f60\u4f60\u8dd1\u5230\u5927\u6392\u6863\u95e8\u53e3\uff0c\u8bdd\u90fd\u4e0d\u8bf4\uff0c\u76f4\u63a5\u628a\u6587\u4ef6\u4e22\u7ed9\u4e86\u8001\u677f\n    \u8001\u677f\u5c31\u7167\u7740\u6587\u4ef6\u91cc\u7684\u6307\u4ee4\u4f9d\u6b21\u5f00\u59cb\u505a<\/code><\/pre>\n<p>\u8fd9\u79cd\u5355\u6587\u4ef6\u91cc\u5806\u780c\u547d\u4ee4\u5b8c\u6210\u4e00\u4e2a\u7cfb\u7edf\u5de5\u4f5c\u7684\u7a0b\u5e8f\uff0c\u6211\u4eec\u79f0\u4e4b\u4e3a\u811a\u672c\u7a0b\u5e8f<\/p>\n<p>\u4ea4\u4e92\u5f0f<\/p>\n<pre><code>[root@web01 ~]# sh  # \u8fd0\u884cbash\u6216sh\u547d\u4ee4\uff0c\u8fdb\u5165shell\u4ea4\u4e92\u5f0f\u73af\u5883\uff0c\nsh-4.2# echo 123\n123\nsh-4.2# echo 666\n666\nsh-4.2# echo 777\n777\nsh-4.2# exit\nexit\n[root@web01 ~]# \n[root@web01 ~]# \n[root@web01 ~]# python # \u8fdb\u5165python\u4ea4\u4e92\u5f0f\u73af\u5883\uff0c\nPython 2.7.5 (default, Oct 14 2020, 14:45:30) \n[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux2\nType &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.\n>&gt;&gt; print(&quot;123&quot;)\n123\n>&gt;&gt; print(&quot;666&quot;)\n666\n>&gt;&gt; print(&quot;777&quot;)\n777\n>&gt;&gt; exit()\n[root@web01 ~]# <\/code><\/pre>\n<p>\u975e\u4ea4\u4e92\u5f0f<\/p>\n<pre><code>\u628a\u4e00\u6761\u6761\u7684\u6307\u4ee4\u5168\u90e8\u90fd\u653e\u5165\u4e00\u4e2a\u6587\u4ef6\u4e2d\uff0c\u7136\u540e\u7528\u89e3\u91ca\u5668\u89e3\u91ca\u6267\u884c\nbash a.sh\npython a.py<\/code><\/pre>\n<p>\u533a\u522b\uff1a<br \/>\n1\u3001\u4ea4\u4e92\u5f0f\u662f\u8fd0\u884c\u4e00\u6761\u547d\u4ee4\u62ff\u5230\u4e00\u6761\u7ed3\u679c\uff0c\u505a\u7684\u4e8b\u60c5\u6bd4\u8f83\u5355\u4e00\uff0c\u7528\u4e8e\u65e5\u5e38\u7ba1\u7406<br \/>\n\u975e\u4ea4\u4e92\u5f0f\u662f\u628a\u4e00\u5806\u547d\u4ee4\u653e\u5230\u4e86\u4e00\u4e2a\u6587\u4ef6\u4e2d\uff0c\u662f\u4e00\u5806\u547d\u4ee4\u5806\u780c\u800c\u6210\u7684\u4e00\u4e2a\u7cfb\u7edf\u6027\u5de5\u4f5c\uff0c\u6bd4\u5982\u6253\u5305\u5907\u4efd\u4e0a\u4f20\u5230\u8fdc\u7a0b\u5907\u4efd\u673a\uff0c\u9700\u8981\u591a\u6761\u547d\u4ee4\u5806\u780c\u8d77\u6765\u5b8c\u6210\u8fd9\u4e2a\u9700\u6c42\u3002<br \/>\n2\u3001\u5185\u7f6e\u73af\u5883\u53d8\u91cfPS1\u5728\u4ea4\u4e92\u5f0f\u73af\u5883\u4e0b\u6709\u503c\uff0c\u5728\u975e\u4ea4\u4e92\u5f0f\u73af\u5883\u4e0b\u4e3a\u7a7a\/\u5e03\u5c14\u503c\u4e3a\u5047<br \/>\n\u4f60\u53ef\u4ee5\u5728\u4ea4\u4e92\u5f0f\u73af\u5883\u6216\u811a\u672c\u6587\u4ef6\u4e2decho $PS1\u6765\u9a8c\u8bc1\uff0c\u8fd9\u53ef\u4ee5\u4f5c\u4e3a\u4ee3\u7801\u4e2d\u8bc6\u522b\u5f53\u524d\u73af\u5883\u662f\u5426\u4e3a\u4ea4\u4e92\u5f0f\u73af\u5883\u7684\u4e00\u79cd\u624b\u6bb5<\/p>\n<pre><code>\u4ea4\u4e92\u5f0f\u4e0b\n[root@web01 ~]# echo $PS1\n\\[\\e[37;40m\\][\\[\\e[32;1m\\]\\u\\[\\e[37xxxxxxxxxxx\n[root@web01 ~]# [ &quot;$PS1&quot; ]\n[root@web01 ~]# echo $?\n0\n\n\u975e\u4ea4\u4e92\u5f0f\u4e0b\n[root@web01 ~]# cat a.sh\necho $PS1\n[ &quot;$PS1&quot; ]\necho $?\n\n[root@web01 ~]# bash a.sh\n\n1<\/code><\/pre>\n<h2>\u4e09 \u53d8\u91cf<\/h2>\n<p>\u767b\u5f55\u7528\u6237\u5373\u8fdb\u5165\u4ea4\u4e92\u5f0f\u73af\u5883\uff0c\u4e0epython\u7684\u4ea4\u4e92\u5f0f\u73af\u5883\u90fd\u662f\u4e00\u56de\u4e8b<\/p>\n<pre><code class=\"language-python\">[root@localhost ~]# x=1\n[root@localhost ~]# x=2\n[root@localhost ~]# echo $x\n2\n\n[root@localhost ~]# name1=egon\n[root@localhost ~]# echo $name1\negon\n[root@localhost ~]# echo ${name1}\negon\n\n[root@localhost ~]# unset name1\n[root@localhost ~]# echo $name1\n\n[root@localhost ~]# \n[root@localhost ~]# domain=www.baidu.com\n[root@localhost ~]# ping -c1 $domain\n\n[root@localhost ~]# name=egon\n[root@localhost ~]# echo &quot;hello $name&quot;\nhello egon<\/code><\/pre>\n<p>\u5e94\u7528\u793a\u4f8b<\/p>\n<pre><code class=\"language-python\">[root@localhost ~]# vim heartbeat.sh\n[root@localhost ~]# cat heartbeat.sh \n#!\/bin\/bash\nip=192.168.11.20\nping -c1 $ip &amp;&gt;\/dev\/null\nif [ $? = 0 ];then\n    echo &quot;host $ip is alive&quot;\nelse\n    echo &quot;host $ip is down!!!&quot;\nfi\n[root@localhost ~]# chmod +x heartbeat.sh \n[root@localhost ~]# .\/heartbeat.sh \nhost 192.168.11.20 is down!!!<\/code><\/pre>\n<h2>\u56db \u5f15\u53f7\u5bf9\u53d8\u91cf\u7684\u5f71\u54cd<\/h2>\n<p>\u53cc\u5f15\u53f7=\u300b\u5f31\u5f15\u7528<\/p>\n<pre><code class=\"language-python\">[root@localhost ~]# name=egon\n[root@localhost ~]# echo &quot;hello $name&quot;<\/code><\/pre>\n<p>\u53cc\u5f15\u53f7=\u300b\u5f3a\u5f15\u7528<\/p>\n<pre><code class=\"language-python\">[root@localhost ~]# echo &#039;hello $name&#039;\nhello $name<\/code><\/pre>\n<p>\u53cd\u5f15\u53f7=\u300b\u53d6\u7ed3\u679c<\/p>\n<pre><code class=\"language-python\">[root@localhost ~]# today=`date +%F`\n[root@localhost ~]# echo $today\n2020-08-11\n\n[root@localhost ~]# today=$(date +%H:%M:%S)\n[root@localhost ~]# echo $today\n22:05:55\n\n\u793a\u4f8b\n[root@localhost ~]# tar czf `date +%F`_bak.tar.gz \/tmp<\/code><\/pre>\n<p>\u53d8\u91cf\u503c\u5305\u542b\u7a7a\u683c\u65f6\uff0c\u9700\u8981\u52a0\u4e0a\u53cc\u5f15\u53f7\u5305\u542b<\/p>\n<pre><code class=\"language-python\">[root@localhost ~]# msg=&quot;hello egon&quot;\n[root@localhost ~]# echo $msg\nhello egon<\/code><\/pre>\n<h2>\u4e94 \u53d8\u91cf\u4f5c\u7528\u57df<\/h2>\n<p>\u73af\u5883\u53d8\u91cf\uff1a  \u5728\u5f53\u524dshell\u53ca\u5b50shell\u751f\u6548\uff01<\/p>\n<p>\u81ea\u5b9a\u4e49\u53d8\u91cf: \u4ec5\u5728\u5f53\u524dshell\u751f\u6548\uff01<\/p>\n<pre><code class=\"language-python\">[root@localhost ~]# x=1\n[root@localhost ~]# export x\n[root@localhost ~]# bash\n[root@localhost ~]# echo $x\n1<\/code><\/pre>\n<p>set  \u67e5\u770b\u6240\u6709\u53d8\u91cf\uff08\u5305\u62ec\u81ea\u5b9a\u53d8\u91cf\u548c\u73af\u5883\u53d8\u91cf\uff09<br \/>\nenv \u67e5\u770b\u73af\u5883\u53d8\u91cf<\/p>\n<p>\u73af\u5883\u53d8\u91cf\u7684\u521d\u59cb\u5316\u6e90\u81ea\u4e8e5\u79cd\u914d\u7f6e\u6587\u4ef6(\u4e0b\u4e00\u5c0f\u8282\u4f1a\u8be6\u7ec6\u4ecb\u7ecd)\uff1a<\/p>\n<pre><code>\/etc\/profile\n\/etc\/profile.d\/*.sh\n\/etc\/bashrc\n~\/.bash_profile\n~\/.bashrc<\/code><\/pre>\n<p>\u7cfb\u7edf\u81ea\u5e26\u73af\u5883\u53d8\u91cf<\/p>\n<pre><code class=\"language-python\">[root@localhost ~]# echo $PS1\n[\\u@\\h \\W]\\$\n[root@localhost ~]# echo $HOSTNAME\nlocalhost.localdomain\n[root@localhost ~]# echo $USER\nroot\n[root@localhost ~]# echo $UID\n0\n[root@localhost ~]# echo $SHELL\n\/bin\/bash\n[root@localhost ~]# echo $HISTSIZE\n5\n[root@localhost ~]# echo $MAIL\n\/var\/spool\/mail\/root\n[root@localhost ~]# echo $PATH\n\/usr\/local\/sbin:\/usr\/local\/bin:\/usr\/sbin:\/usr\/bin:\/root\/bin<\/code><\/pre>\n<h2>\u516d \u767b\u5f55shell\u4e0e\u975e\u767b\u5f55shell\uff08\u52a0\u8f7d\u914d\u7f6e\u7684\u4e0d\u540c\uff09<\/h2>\n<p>1\u3001\u6309\u7167shell\u63a5\u6536\u6307\u4ee4\u7684\u5f62\u5f0f\u4e0a\u7684\u4e0d\u540c\uff0c\u6211\u4eec\u4e4b\u524d\u628ashell\u5206\u4e3a\u4ea4\u4e92\u5f0f\u4e0e\u975e\u4ea4\u4e92\u5f0f<\/p>\n<p>2\u3001\u6309\u7167\u8fdb\u5165shell\u73af\u5883\u7684\u65b9\u5f0f\u7684\u4e0d\u540c\uff0c\u6211\u4eec\u53ef\u4ee5\u628ashell\u5206\u4e3a\u767b\u5f55\u5f0f\u4e0e\u975e\u767b\u5f55\u5f0f<\/p>\n<pre><code># 1\u3001\u767b\u9646\u5f0fshell\uff08\u65e5\u5e38\u6700\u591a\uff09:\n\u7528\u6237\u5728\u767b\u5f55\u65f6\u542f\u52a8\u7684shell\uff0c\u4f8b\u5982\u7ec8\u7aef\u6a21\u62df\u5668\uff0c\u5982ssh\uff0c\u6216\u8005\u5728\u63a7\u5236\u53f0\u76f4\u63a5\u8f93\u5165\u7684\u7528\u6237\u540d\u548c\u5bc6\u7801\u3002\n# 2\u3001\u975e\u767b\u9646\u5f0fshell\n\u767b\u5f55\u540e\u88ab\u7528\u6237\u624b\u52a8\u542f\u52a8\u7684shell\uff0c\u4f8b\u5982\u5728\u7ec8\u7aef\u4e2d\u76f4\u63a5\u8f93\u5165bash\u6216sh\u547d\u4ee4\u3002<\/code><\/pre>\n<p>\u4ea4\u4e92\u5f0f\u4e0e\u975e\u4ea4\u4e92\u5f0f\u7684\u6838\u5fc3\u533a\u522b\u5c31\u662f\u63a5\u6536\u6307\u4ee4\u7684\u5f62\u5f0f\u4e0a\u7684\u4e0d\u540c\uff0c\u800c\u767b\u5f55\u5f0f\u4e0e\u975e\u767b\u5f55\u7684\u6838\u5fc3\u533a\u522b\u8868\u9762\u662f\u8fdb\u5165shell\u73af\u5883\u7684\u5f62\u5f0f\u4e0a\u7684\u4e0d\u540c\uff0c\u4f46\u5b9e\u9645\u4e0a\u7684\u533a\u522b\u662f\u8bfb\u53d6\u4e0e\u6267\u884c\u7684\u914d\u7f6e\u6587\u4ef6\u7684\u4e0d\u540c<br \/>\n\u89e3\u91ca<\/p>\n<pre><code>\u4f46\u51e1\u8fdb\u5165\u5230\u67d0\u4e00\u4e2ashell\u73af\u5883\u4e2d\uff0c\u672c\u8d28\u4e0a\u90fd\u662f\u542f\u52a8\u4e86\u4e00\u4e2ashell\u8fdb\u7a0b\uff0c\n\u6bcf\u4e2a\u8fdb\u7a0b\u542f\u52a8\u65f6\u90fd\u5fc5\u987b\u4ee5\u67d0\u4e2a\u7528\u6237\u8eab\u4efd\u542f\u52a8\u4ee5\u6807\u8bc6\u4f5c\u4e3a\u5176\u5728\u7cfb\u7edf\u4e2d\u8bc6\u522b\u6743\u9650\u7684\u4f9d\u636e\uff0c\n\u800clinux\u7cfb\u7edf\u4e2d\u4e00\u5207\u7686\u4e3a\u6587\u4ef6\uff0c\u4e00\u4e2a\u7528\u6237\u662f\u7531\u4e00\u7cfb\u5217\u6587\u4ef6\u6784\u6210\u7684\n\n\u6240\u4ee5\uff0c\u5f53\u4f60\u4f60\u4ee5\u4e0d\u540c\u7684\u65b9\u5f0f\u8fdb\u5165shell\u73af\u5883\u4e2d\u65f6\uff0c\u64cd\u4f5c\u7cfb\u7edf\u5982\u4f55\u533a\u5206\uff1f\n\u7b54\uff1a\u5c31\u662f\u901a\u8fc7\u52a0\u8f7d\u4e0d\u540c\u914d\u7f6e\u6587\u4ef6\u6765\u533a\u5206\u7684\uff0c\u8fd9\u4e9b\u914d\u7f6e\u6587\u4ef6\u7528\u4e8e\u521d\u59cb\u5316\u6216\u4fdd\u5b58\u5f53\u524dshell\u7684\u5de5\u4f5c\u73af\u5883<\/code><\/pre>\n<p>shell\u73af\u5883\u76f8\u5173\u914d\u7f6e\u6587\u4ef6\u5c31\u4ee5\u4e0b\u51e0\u79cd<\/p>\n<pre><code># 1\u3001\u7cfb\u7edf\u7ea7\u914d\u7f6e\n\/etc\/profile\n\/etc\/profile.d\/*.sh\n\/etc\/bashrc \n\n# 2\u3001\u7528\u6237\u7ea7\u914d\u7f6e\n~\/.bash_profile\n~\/.bashrc\n\n# \u8865\u5145\u8bf4\u660e\uff1a\n1\u3001profile\u7c7b\u6587\u4ef6, \u8bbe\u5b9a\u73af\u5883\u53d8\u91cf, \u767b\u9646\u524d\u8fd0\u884c\u7684\u811a\u672c\u548c\u547d\u4ee4\u3002\n\n2\u3001bashrc\u7c7b\u6587\u4ef6, \u8bbe\u5b9a\u672c\u5730\u53d8\u91cf, \u5b9a\u4e49\u547d\u4ee4\u522b\u540d\n\n3\u3001\u5982\u679c\u5168\u5c40\u914d\u7f6e\u548c\u4e2a\u4eba\u914d\u7f6e\u4ea7\u751f\u51b2\u7a81\uff0c\u4ee5\u4e2a\u4eba\u914d\u7f6e\u4e3a\u51c6\u3002<\/code><\/pre>\n<p>\u5f71\u54cdbash shell\u7684\u6587\u4ef6\uff08\/etc\u4e0b\u7684\u662f\u7cfb\u7edf\u7ea7\u7684\u6587\u4ef6\uff0c\u5bb6\u76ee\u5f55\u4e0b\u7684\u662f\u7528\u6237\u7ea7\uff09&#8212;\u300bcentos7.9<\/p>\n<pre><code class=\"language-python\">\u5f53\u7528\u6237\u901a\u8fc7\u7528\u6237\u540d\u548c\u5bc6\u7801\u767b\u5f55\u7cfb\u7edf\u6216\u8005su - egon\u65f6\uff0c\u7cfb\u7edf\u4f1a\u542f\u52a8\u4e00\u4e2alogin Shell\uff0c\u4f9d\u6b21\u52a0\u8f7d\u5982\u4e0b\u914d\u7f6e\n    1. \/etc\/profile    # \u5185\u90e8\u4f1a\u8c03\u7528\/etc\/profile.d\u4e0b\u7684\u811a\u672c\uff0c\u5982\u679c\u662fcentos9.3\u5219\u8fd8\u4f1a\u591a\u8c03\u7528\u4e00\u6b21\/etc\/bashrc\n    2. ~\/.bash_profile      \n    3. ~\/.bashrc       # \u5185\u90e8\u518d\u8c03\u7528\/etc\/bashrc<\/code><\/pre>\n<p>\u5728\u975e\u767b\u5f55shell\u5373su egon\u65f6<\/p>\n<pre><code class=\"language-python\">non-login shell\u4f9d\u6b21\u52a0\u8f7d\u5982\u4e0b\u914d\u7f6e\n    1\u3001~\/.bashrc    # \u5185\u4f1a\u4f9d\u6b21\u8c03\u7528\/etc\/bashrc\u3001\/etc\/profile.d\/*.sh\n\n\u4e86\u89e3\u77e5\u8bc6\uff1a\u770b\u4ee3\u7801\u89e3\u6790\u8c03\u7528\u987a\u5e8f\n    ~\/.bashrc    \u5185\u90e8\u4f1a\u8c03\u7528 \/etc\/bashrc \uff0c\u800c\/etc\/bashrc\u5185\u90e8\u4f1a\u8c03\u7528\/etc\/profile.d\/\u4e0b\u7684\u811a\u672c\n    \u4ee3\u7801\u89e3\u6790\u5982\u4e0b\n    \u53ef\u4ee5\u770b\u4e00\u4e0b\uff1a\/etc\/bashrc\u7684\u6587\u4ef6\u4e2d\u7684\u7b2c54\u884c\u589e\u52a0\u4e86\u5982\u4e0b\u4ee3\u7801\n    if ! shopt -q login_shell\u6ee1\u8db3\u5f53\u524dshell\u4e0d\u7b49\u4e8elogin_shell,\u5373\u975e\u767b\u5f55shell\u65f6\n    \u4f1a\u6267\u884c\u5230\u7b2c75\u884c\u7684for\u5faa\u73af\u6267\u884c\/etc\/profile.d\/*.sh\n    \u4e5f\u5c31\u662f\u8bf4\u5728\u8fdb\u5165\u975e\u767b\u5f55\u5f0fshell\u65f6\uff0c\u9664\u4e86\u6267\u884c\n    ~\/.bashrc \n    \/etc\/basrh\n    \u8fd8\u4f1a\u6267\u884c\uff1a\/etc\/profile.d\/*.sh<\/code><\/pre>\n<p>\u5f3a\u8c03\uff1a<br \/>\n\u4f60\u5fc5\u987b\u907f\u514d\u5728\u4e0a\u8ff0\u6587\u4ef6\u4e2d\u6dfb\u52a0\u4efb\u4f55\u4f1a\u4ea7\u751f\u8f93\u51fa\u7684\u547d\u4ee4\uff08\u4f8b\u5982echo\u547d\u4ee4\uff09\uff0c\u5426\u5219\u4f1a\u5e72\u6270scp\u6216\u8005\u5176\u4ed6\u4f9d\u8d56ssh\u7684\u547d\u4ee4\u7684\u6267\u884c\uff0c\u8fd8\u6709\u540e\u7eed\u8981\u5b66\u7684rsync\u547d\u4ee4\u3002\u539f\u7406\u6211\u4eec\u5c06\u5728\u540e\u7eed\u7ae0\u8282\u5b66\u4e60\u5230<\/p>\n<pre><code>\u5982\u679c\u4f60\u786e\u5b9e\u9700\u8981\u5728bashrc\u6587\u4ef6\u4e2d\u6dfb\u52a0echo\u6216\u7c7b\u4f3c\u7684\u547d\u4ee4\uff0c\n\u4e00\u4e2a\u6bd4\u8f83\u597d\u7684\u505a\u6cd5\u53ef\u80fd\u662f\u68c0\u67e5\u5f53\u524d\u4f1a\u8bdd\u662f\u5426\u4e3a\u4e00\u4e2a\u4ea4\u4e92\u5f0f\u4f1a\u8bdd\uff0c\n\u53ea\u5728\u4ea4\u4e92\u5f0f\u4f1a\u8bdd\u4e2d\u6267\u884c\u8fd9\u4e9b\u547d\u4ee4\u3002\u4f60\u53ef\u4ee5\u53c2\u8003\u4ee5\u4e0b\u7684bash\u8bed\u53e5\uff1a\nif [ &quot;$PS1&quot; ]; then\n  echo &quot;This is an interactive session.&quot;\nfi\n\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c$PS1\u73af\u5883\u53d8\u91cf\u901a\u5e38\u5728\u4ea4\u4e92\u5f0fbash\u4f1a\u8bdd\u4e2d\u88ab\u8bbe\u7f6e\uff0c\n\u6240\u4ee5\u4f60\u53ef\u4ee5\u4f7f\u7528\u5b83\u6765\u68c0\u6d4b\u5f53\u524d\u4f1a\u8bdd\u662f\u5426\u4e3a\u4ea4\u4e92\u5f0f\u3002\n\u7c7b\u4f3c\u7684\uff0c\u4f60\u53ef\u4ee5\u628a\u4f60\u7684echo\u547d\u4ee4\u653e\u5728\u8fd9\u6837\u7684\u6761\u4ef6\u5224\u65ad\u8bed\u53e5\u4e2d\uff0c\n\u4ee5\u907f\u514d\u5728\u975e\u4ea4\u4e92\u5f0f\u4f1a\u8bdd\uff08\u6bd4\u5982scp\u548cssh\u547d\u4ee4\uff09\u4e2d\u6267\u884c\u5b83\u4eec\u3002<\/code><\/pre>\n<p>Ps:<\/p>\n<pre><code class=\"language-python\">1\u3001vim \/home\/user1\/.bash_history -------\u6bcf\u6b21\u767b\u9646\u7528\u6237\u7684\u64cd\u4f5c\u90fd\u8bb0\u5f55\u5176\u4e2d\n2\u3001su - user1\u8fdb\u884c\u64cd\u4f5c\u7136\u540e\u9000\u51fa\uff0c\u67e5\u770b\u8be5\u6587\u4ef6\u5185\u5bb9\n3\u3001vim \/home\/user1\/.bash_logout --------\u6dfb\u52a0\u4e00\u6761  \n4\u3001&gt;\/home\/user1\/.bash_history\u8fd9\u6837\u6bcf\u6b21\u9000\u51fa\u7528\u6237\u540e\u90fd\u4f1a\u81ea\u52a8\u6e05\u7a7a~\/.bash_history\u4e2d\u7684\u5185\u5bb9   <\/code><\/pre>\n<h2>\u4e03 \u5143\u5b57\u7b26<\/h2>\n<p>shell\u8bed\u6cd5\u4e2d\u7684\u7279\u6b8a\u5b57\u7b26<\/p>\n<ul>\n<li>\n<p>1\u3001&#8220; \u4e0e$()\uff1a\u53d6\u547d\u4ee4\u7684\u7ed3\u679c<\/p>\n<pre><code class=\"language-python\">[root@localhost ~]# echo <code>pwd<\/code>\n\/root\n[root@localhost ~]# echo $(pwd)\n\/root\n\n\u4e0d\u4e00\u6837\u7684\u5730\u65b9\u5728\u4e8e$()\u53ef\u4ee5\u5d4c\u5957\uff0c\u800c``\u4e0d\u80fd\u5d4c\u5957\n[root@localhost ~]# echo $(ls $(pwd))<\/code><\/pre>\n<\/li>\n<li>\n<p>2\u3001~\u5bb6\u76ee\u5f55<\/p>\n<\/li>\n<li>\n<p>3\u3001.\u4e0e..<\/p>\n<\/li>\n<li>\n<p>4\u3001!\u53d6\u53cd<\/p>\n<pre><code class=\"language-python\">[root@localhost ~]# touch \/test\/{1.txt,2.txt,a.txt,aaa_bbb.txt}\n[root@localhost ~]# find \/test ! -name 1.txt\n\/test\n\/test\/2.txt\n\/test\/a.txt\n\/test\/aaa_bbb.txt\n\n[root@localhost ~]# ls \/test\/[!0-9].txt  # .txt\u524d\u53ea\u6709\u4e00\u4e2a\u5b57\u7b26\uff0c\u4f46\u662f\u975e\u6570\u5b57\n\/test\/a.txt\n[root@localhost ~]# ls \/test\/[^0-9].txt  # .txt\u524d\u53ea\u6709\u4e00\u4e2a\u5b57\u7b26\uff0c\u4f46\u662f\u975e\u6570\u5b57\n\/test\/a.txt<\/code><\/pre>\n<\/li>\n<li>\n<p>5\u3001@\u65e0\u7279\u6b8a\u610f\u4e49<\/p>\n<\/li>\n<li>\n<p>6\u3001#\u6ce8\u91ca<\/p>\n<\/li>\n<li>\n<p>4\u3001$\u53d6\u53d8\u91cf\u503c<\/p>\n<pre><code class=\"language-python\">[root@localhost ~]# x=1\n[root@localhost ~]# echo $x\n1<\/code><\/pre>\n<\/li>\n<li>\n<p>5\u3001%\u3001-\u3001+\u8fd0\u7b97\u7b26<\/p>\n<pre><code class=\"language-python\"># \u6570\u5b66\u8fd0\u7b97\n# 1\u3001bc\u662f\u6bd4\u8f83\u5e38\u7528\u7684linux\u8ba1\u7b97\u5de5\u5177\u4e86\uff0c\u800c\u4e14\u652f\u6301\u6d6e\u70b9\u8fd0\u7b97\uff1a\n[root@localhost ~]# res=<code>echo 1+1 | bc<\/code>\n[root@localhost ~]# echo $res\n2\n\n[root@localhost ~]# res=<code>echo 10 % 3 | bc<\/code>\n[root@localhost ~]# echo $res\n1\n\n[root@localhost ~]# res=<code>echo 1.2+1.3|bc<\/code>\n[root@localhost ~]# echo $res\n2.5\n\n[root@localhost ~]# res=<code>echo 5.0+3.0|bc<\/code>\n[root@localhost ~]# echo $res\n8.0\n\n[root@localhost ~]# res=<code>echo &quot;scale=2;5.0\/3.0&quot;|bc<\/code>\n[root@localhost ~]# echo $res\n1.66\n\n[root@localhost ~]# res=<code>echo &quot;scale=2;5.0\/6.0&quot;|bc<\/code>\n[root@localhost ~]# echo $res\n.83\n\n# 2\u3001expr\u4e0d\u652f\u6301\u6d6e\u70b9\u6570\u8ba1\u7b97\u3002\u800c\u4e14\u8981\u6ce8\u610f\u6570\u5b57\u4e0e\u8fd0\u7b97\u7b26\u4e2d\u7684\u7a7a\u683c\n[root@localhost ~]# res=<code>expr 5 \/ 3<\/code>  # \u4e0d\u652f\u6301\u6d6e\u70b9\u8ba1\u7b97\n[root@localhost ~]# echo $res\n1\n\n[root@localhost ~]# res=<code>expr 1+1<\/code>  # \u6ce8\u610f\uff1a\u8981\u6709\u7a7a\u683c\n[root@localhost ~]# echo $res\n1+1\n[root@localhost ~]# res=<code>expr 1 + 1<\/code>\n[root@localhost ~]# echo $res\n2\n\n# 3\u3001$(()) \u540cexpr\uff0c\u4e0d\u652f\u6301\u6d6e\u70b9\u6570\u8fd0\u7b97\n[root@localhost ~]# echo $((1+1))\n2\n[root@localhost ~]# echo $((1.0+2.0))\n-bash: 1.0+2.0: \u8bed\u6cd5\u9519\u8bef: \u65e0\u6548\u7684\u7b97\u672f\u8fd0\u7b97\u7b26 \uff08\u9519\u8bef\u7b26\u53f7\u662f \".0+2.0\"\uff09\n\n#4\u3001let \u4e0d\u652f\u6301\u6d6e\u70b9\u6570\u8fd0\u7b97\uff0c\u800c\u4e14\u4e0d\u652f\u6301\u76f4\u63a5\u8f93\u51fa\uff0c\u53ea\u80fd\u8d4b\u503c\n[root@localhost ~]# let res=1+1\n[root@localhost ~]# echo $res\n2\n[root@localhost ~]# \n[root@localhost ~]# let res=50\/5\n[root@localhost ~]# echo $res\n10\n[root@localhost ~]# let c=1.3*3\n-bash: let: c=1.3*3: \u8bed\u6cd5\u9519\u8bef: \u65e0\u6548\u7684\u7b97\u672f\u8fd0\u7b97\u7b26 \uff08\u9519\u8bef\u7b26\u53f7\u662f \".3*3\"<\/code><\/pre>\n<\/li>\n<li>\n<p>6\u3001^\u540c!\u4e00\u6837<\/p>\n<\/li>\n<li>\n<p>7\u3001*\u4efb\u610f\u591a\u4e2a\u5b57\u7b26<\/p>\n<pre><code class=\"language-python\">[root@localhost ~]# touch 1.txt 2.txt aa.txt aaa.txt\n[root@localhost ~]# rm -rf *.txt\n[root@localhost ~]# touch 1.txt 2.txt aa.txt aaa.txt a1c.txt\n[root@localhost ~]# ls *.txt\n1.txt  2.txt  a1c.txt  aaa.txt  aa.txt<\/code><\/pre>\n<\/li>\n<li>\n<p>8\u3001()\u5728\u5b50shell\u4e2d\u6267\u884c<\/p>\n<pre><code class=\"language-python\">[root@localhost ~]# (x=1)\n[root@localhost ~]# echo $x\n\n\u5e94\u7528\n[root@localhost ~]# (umask 066;touch a.txt)  # umask\u7684\u8bbe\u7f6e\u53ea\u5728\u5b50shell\u4e2d\u6709\u6548\n[root@localhost ~]# ll a.txt \n-rw-------. 1 root root 0 8\u6708  13 15:22 a.txt\n[root@localhost ~]# touch b.txt\n[root@localhost ~]# ll b.txt \n-rw-r--r--. 1 root root 0 8\u6708  13 15:23 b.txt<\/code><\/pre>\n<\/li>\n<li>\n<p>9\u3001_\u4e0b\u5212\u7ebf\uff1a\u65e0\u7279\u6b8a\u610f\u4e49\uff0c\u53ef\u4ee5\u7528\u4e8e\u540d\u5b57\u7684\u58f0\u660e<\/p>\n<\/li>\n<li>\n<p>10\u3001=\u8d4b\u503c\uff0c\u5224\u65ad\u76f8\u7b49\u6027<\/p>\n<pre><code class=\"language-python\">[root@localhost ~]# [ 1 = 1 ]  # \u6761\u4ef61 = 1\u7684\u5de6\u53f3\u4e24\u8fb9\u5fc5\u987b\u6709\u7a7a\u683c\n[root@localhost ~]# echo $?    # \u5224\u65ad\u4e0a\u4e00\u6761\u547d\u4ee4\u7684\u7ed3\u679c\u662f\u5426\u4e3a\u771f\uff0c0=\u300btrue\n0<\/code><\/pre>\n<\/li>\n<li>\n<p>11\u3001|\u7ba1\u9053\uff1a\u628a\u4e00\u4e2a\u8fdb\u7a0b\u7684\u5904\u7406\u7ed3\u679c\u4f20\u9012\u7ed9\u53e6\u5916\u4e00\u4e2a\u8fdb\u7a0b<\/p>\n<pre><code class=\"language-python\">[root@localhost ~]# ps aux | grep python\n\nxargs\u53c2\u6570\u4f20\u9012\uff0c\u628a\u4e0a\u4e00\u4e2a\u547d\u4ee4\u7684\u7ed3\u679c\u4f5c\u4e3a\u4e0b\u4e00\u4e2a\u547d\u4ee4\u7684\u53c2\u6570\n[root@localhost ~]# find \/home\/ -type d -name \"test*\" |xargs ls\n1.txt  2.txt  3.txt\n[root@localhost ~]# ls \/home\/test\n1.txt  2.txt  3.txt<\/code><\/pre>\n<\/li>\n<li>\n<p>12\u3001\\\u8f6c\u4e49\u7279\u6b8a\u5b57\u7b26<\/p>\n<pre><code class=\"language-python\">[root@localhost ~]# mkdir a\\ b.txt  # \u867d\u7136\u53ef\u4ee5\uff0c\u4f46\u4e0d\u63a8\u8350\n[root@localhost ~]# ll\n\u603b\u7528\u91cf 0\ndrwxr-xr-x. 2 root root 6 8\u6708  13 15:35 a b.txt\n\n[root@localhost ~]# echo $RMB  # \u9ed8\u8ba4\u4f1a\u5f53\u6210\u53d8\u91cf\n\n[root@localhost ~]# echo '$RMB'  # \u53d6\u6d88\u7279\u6b8a\u610f\u4e49\n$RMB\n[root@localhost ~]# echo \\$RMB  # \u53d6\u6d88\u7279\u6b8a\u610f\u4e49\n$RMB<\/code><\/pre>\n<\/li>\n<li>\n<p>13\u3001[]\u6761\u4ef6\u6d4b\u8bd5\uff0c\u540e\u7eed\u4f1a\u8be6\u7ec6\u4ecb\u7ecd<\/p>\n<pre><code class=\"language-python\">[root@localhost ~]# name=\"egon\"\n[root@localhost ~]# [ $name = \"egon\" ];echo $?\n0\n[root@localhost ~]# name=\"adf\"\n[root@localhost ~]# [ $name = \"egon\" ];echo $?\n1\n\n[root@localhost ~]# [ -d \/test ];echo $?<\/code><\/pre>\n<\/li>\n<li>\n<p>14\u3001\u5f15\u53f7<\/p>\n<pre><code class=\"language-python\">''  \u5f3a\u5f15\u7528\uff08\u5728\u5355\u5f15\u53f7\u4e2d\u90fd\u89c6\u4e3a\u666e\u901a\u5b57\u7b26\uff09\n\" \" \u5f31\u5f15\u7528 \uff08\u5728\u53cc\u5f15\u53f7\u4e2d\u4fdd\u7559\u53d8\u91cf\uff09\n\n[root@localhost ~]# x=111\n[root@localhost ~]# echo \"$x\"\n111\n[root@localhost ~]# echo '$x'\n$x\n[roo<\/code><\/pre>\n<\/li>\n<li>\n<p>15\u3001;\u4e0e&amp;&amp;\u4e0e||\u8fde\u63a5\u591a\u6761\u547d\u4ee4<\/p>\n<pre><code class=\"language-python\">[root@localhost home]# gagaga;ls  # \u4e0d\u8bba\u524d\u4e00\u6761\u547d\u4ee4\u8fd0\u884c\u6210\u529f\u4e0e\u5426\uff0c\u90fd\u4f1a\u6267\u884c\u540e\u7eed\u547d\u4ee4\nbash: gagaga: \u672a\u627e\u5230\u547d\u4ee4...\negon\n[root@localhost home]# gagaga && ls  # \u53ea\u6709\u524d\u4e00\u6761\u547d\u4ee4\u6267\u884c\u6210\u529f\uff0c\u624d\u4f1a\u6267\u884c\u540e\u7eed\u547d\u4ee4\nbash: gagaga: \u672a\u627e\u5230\u547d\u4ee4...\n\n[root@localhost home]# ls \/test || mkdir \/test  # \u524d\u4e00\u6761\u547d\u4ee4\u6267\u884c\u4e0d\u6210\u529f\u624d\u4f1a\u6267\u884c\u540e\u7eed\u547d\u4ee4\n0.txt  1.txt  2.txt  3.txt  4.txt  5.txt  6.txt  7.txt  8.txt  9.txt<\/code><\/pre>\n<\/li>\n<li>\n<p>16\u3001\/\u8def\u5f84\u5206\u9694\u7b26<\/p>\n<\/li>\n<li>\n<p>17\u3001{}\u5305\u542b<\/p>\n<pre><code class=\"language-python\">[root@localhost home]# touch \/test\/{0..9}.txt\n[root@localhost home]# ls \/test\/\n0.txt  1.txt  2.txt  3.txt  4.txt  5.txt  6.txt  7.txt  8.txt  9.txt<\/code><\/pre>\n<\/li>\n<li>\n<p>18\u3001&amp;\u540e\u53f0\u8fd0\u884c<\/p>\n<pre><code class=\"language-python\">[root@localhost home]# echo \"hello\";sleep 3;echo \"world\" &<\/code><\/pre>\n<\/li>\n<li>\n<p>19\u3001\u91cd\u5b9a\u5411<\/p>\n<pre><code class=\"language-python\">> >> \u8f93\u51fa\u91cd\u5b9a\u5411\n< << \u8f93\u5165\u91cd\u5b9a\u5411\n\n> \u8986\u76d6  >> \u8ffd\u52a0\n[root@localhost home]# cat >> a.txt << EOF\n> 111\n> 222\n> 333\n> EOF\n\n0\u6807\u51c6\u8f93\u5165\u30011\u6807\u51c6\u6b63\u786e\u8f93\u51fa\u30012\u6807\u51c6\u9519\u8bef\u8f93\u51fa\uff0c&\u6807\u51c6\u6b63\u786e\u548c\u9519\u8bef\u8f93\u51fa\n[root@localhost home]# pwd 1>a.txt\n[root@localhost home]# cat a.txt \n\/home\n[root@localhost home]# gagag 2>a.txt\n[root@localhost home]# cat a.txt \nbash: gagag: \u672a\u627e\u5230\u547d\u4ee4...\n[root@localhost home]# gagaga &>\/dev\/null\n\n< << \u8f93\u5165\u91cd\u5b9a\u5411\n[root@localhost ~]# mysql -uroot -p123 < bbs.sql\n[root@localhost home]# grep root < \/etc\/passwd\nroot:x:0:0:root:\/root:\/bin\/bash\noperator:x:11:0:operator:\/root:\/sbin\/nologin\n\n[root@localhost home]# dd if=\/dev\/zero of=\/a.txt bs=1M count=10\n\u8bb0\u5f55\u4e8610+0 \u7684\u8bfb\u5165\n\u8bb0\u5f55\u4e8610+0 \u7684\u5199\u51fa\n10485760\u5b57\u8282(10 MB)\u5df2\u590d\u5236\uff0c0.024387 \u79d2\uff0c430 MB\/\u79d2\n[root@localhost home]# dd <\/dev\/zero >\/b.txt bs=1M count=10\n\u8bb0\u5f55\u4e8610+0 \u7684\u8bfb\u5165\n\u8bb0\u5f55\u4e8610+0 \u7684\u5199\u51fa\n10485760\u5b57\u8282(10 MB)\u5df2\u590d\u5236\uff0c0.0202365 \u79d2\uff0c518 MB\/\u79d2\n\n[root@localhost home]# ll \/a.txt \n-rw-r--r--. 1 root root 10485760 8\u6708  13 16:02 \/a.txt\n[root@localhost home]# ll \/b.txt \n-rw-r--r--. 1 root root 10485760 8\u6708  13 16:03 \/b.txt<\/code><\/pre>\n<\/li>\n<li>\n<p>20\u3001?\u4efb\u610f\u4e00\u4e2a\u5b57\u7b26<\/p>\n<pre><code class=\"language-python\">[root@localhost ~]# ls ??.txt\naa.txt\n[root@localhost ~]# ls a?c.txt\na1c.txt\n[root@localhost ~]# rm -rf *.txt<\/code><\/pre>\n<\/li>\n<li>\n<p>21\u3001\u8303\u56f4\u4e2d\u7684\u4efb\u610f\u4e00\u4e2a\u5b57\u7b26 [12] [ac] [a-z] [0-9]<\/p>\n<pre><code class=\"language-python\">[root@localhost ~]# touch a1c a2c axc aXc axd\n[root@localhost ~]# ls a?c\na1c  a2c  axc  aXc\n[root@localhost ~]# ls a[1x]c\na1c  axc\n[root@localhost ~]# ls a[a-z]c\naxc  aXc\n[root@localhost ~]# ls a[A-Z]c  # \u4e0d\u533a\u5206\u5927\u5c0f\u5199\naxc  aXc\n[root@localhost ~]# ls a[x]c\naxc\n[root@localhost ~]# ls a[X]c\naXc\n[root@localhost ~]# ls a[0-9]c\na1c  a2c\n[root@localhost ~]# ls \/dev\/sd[a-z]*\n\/dev\/sda  \/dev\/sda1  \/dev\/sda2  \/dev\/sda3  \/dev\/sdb1<\/code><\/pre>\n<\/li>\n<\/ul>\n<h2>\u516b Bash SHELL\u57fa\u7840<\/h2>\n<p>\u4f8b1<\/p>\n<pre><code class=\"language-python\">[root@localhost ~]# vim if.sh\n[root@localhost ~]# cat if.sh \n#!\/usr\/bin\/env bash\ndomain=&quot;www.baidu.com&quot;\nping -c2 $domain &amp;&gt;\/dev\/null\n\nif [ $? = 0 ];then\n    echo &quot;network is ok&quot;\nelse\n    echo &quot;network is down!!!&quot;\nfi\n[root@localhost ~]# chmod +x if.sh \n[root@localhost ~]# .\/if.sh \nnetwork is ok<\/code><\/pre>\n<p>\u4f8b2<\/p>\n<pre><code class=\"language-python\">[root@localhost ~]# vim for.sh\n[root@localhost ~]# ll for.sh \n-rw-r--r--. 1 root root 61 8\u6708  13 16:17 for.sh\n[root@localhost ~]# . for.sh \negon\ntom\njack<\/code><\/pre>\n<p>\u4f8b3<\/p>\n<pre><code class=\"language-python\">[root@localhost ~]# vim for1.sh \n[root@localhost ~]# cat for1.sh \n#!\/bin\/bash\nfor i in {1..5}\ndo\n    echo $i\ndone\n[root@localhost ~]# source for1.sh \n1\n2\n3\n4\n5<\/code><\/pre>\n<p>\u4f8b4<\/p>\n<pre><code class=\"language-python\">[root@localhost ~]# vim for2.sh \n[root@localhost ~]# cat for2.sh \n#!\/bin\/bash\nfor i in {1..10}\ndo\n    ip=192.168.12.$i\n    ping -c1 $ip &amp;&gt;\/dev\/null\n    if [ $? = 0 ];then\n        echo &quot;$i is up&quot;\n    else\n        echo &quot;$i is down!!!&quot;\n    fi\ndone\n[root@localhost ~]# vim for2.sh \n[root@localhost ~]# source for2.sh \n192.168.12.1 is up\n192.168.12.2 is down!!!\n192.168.12.3 is up\n192.168.12.4 is down!!!\n......<\/code><\/pre>\n<p>\u7ec3\u4e60<\/p>\n<pre><code class=\"language-python\">1\u3001\u7f16\u5199\u811a\u672c\u521b\u5efa100\u4e2a\u7528\u6237\u5e76\u8bbe\u7f6e\u597d\u5bc6\u7801\uff0c\u7528\u6237\u540d\u4e3auser1\uff0cuser2\uff0cuser3...\n\n\u63d0\u793a\u975e\u4ea4\u4e92\u5f0f\u4fee\u6539\u5bc6\u7801\uff1a echo 123 |passwd user1 --stdin<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Bash shell\u57fa\u7840 \u4e00 \u4ecb\u7ecd \u7c7b\u6bd4\uff1a shell\u8bed\u6cd5\u300a==============\u300bpython\u8bed\u6cd5 b [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":32,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[31],"tags":[21,19,35,22,20],"_links":{"self":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts\/233"}],"collection":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=233"}],"version-history":[{"count":9,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts\/233\/revisions"}],"predecessor-version":[{"id":9068,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts\/233\/revisions\/9068"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/media\/32"}],"wp:attachment":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=233"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=233"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=233"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}