{"id":391,"date":"2021-07-28T16:24:03","date_gmt":"2021-07-28T08:24:03","guid":{"rendered":"http:\/\/egonlin.com\/?p=391"},"modified":"2024-05-06T22:18:43","modified_gmt":"2024-05-06T14:18:43","slug":"%e7%ac%ac%e4%ba%8c%e8%8a%82%ef%bc%9a%e5%85%83%e5%ad%97%e7%ac%a6","status":"publish","type":"post","link":"https:\/\/egonlin.com\/?p=391","title":{"rendered":"\u7b2c\u4e8c\u8282\uff1a\u5143\u5b57\u7b26"},"content":{"rendered":"<h1>\u5143\u5b57\u7b26<\/h1>\n<p>\u5143\u5b57\u7b26\u6307\u7684\u662f\u80fd\u591f\u88abshell\u89e3\u91ca\u7684\u7279\u6b8a\u5b57\u7b26\uff0c\u6bcf\u4e2a\u7279\u6b8a\u5b57\u7b26\u90fd\u6709\u5176\u7279\u6b8a\u542b\u4e49\uff0c\u8fd9\u4e9b\u5b57\u7b26\u4e00\u65b9\u9762\u53ef\u7528\u4e8e\u53d8\u91cf\u503c\u7684\u8fd0\u7b97\u3001\u6211\u4eec\u53ef\u4ee5\u79f0\u4e4b\u4e3a\u8fd0\u7b97\u7b26\uff0c\u53e6\u5916\u4e00\u65b9\u9762\u53ef\u4ee5\u548cshell\u547d\u4ee4\u914d\u5408\u4f7f\u7528\u6765\u8fbe\u5230\u66f4\u9ad8\u7ea7\u7684\u6548\u679c<\/p>\n<h2>\u4e00 \u7b97\u6570\u8fd0\u7b97\u7b26<\/h2>\n<p>\u8fd0\u7b97\u7b26<\/p>\n<ul>\n<li>+<\/li>\n<li>&#8211;<\/li>\n<li>*<\/li>\n<li>\/<\/li>\n<li>%<\/li>\n<\/ul>\n<p>\u7b97\u6570\u8fd0\u7b97\u7b26\u9700\u8981\u914d\u5408\u4e0b\u8ff0\u64cd\u4f5c\u4f7f\u7528<\/p>\n<pre><code class=\"language-python\"># \u6d6e\u70b9\u8fd0\u7b97\r\nbc  \r\n\r\n# \u6574\u6570\u8fd0\u7b97\r\nexpr\r\n$(())\r\n$[]\r\nlet<\/code><\/pre>\n<p>\u8be6\u89e3\u5982\u4e0b<\/p>\n<ul>\n<li>1\u3001bc\u662f\u6bd4\u8f83\u5e38\u7528\u7684linux\u8ba1\u7b97\u5de5\u5177\u4e86\uff0c\u800c\u4e14\u652f\u6301\u6d6e\u70b9\u8fd0\u7b97\n<pre>[root@localhost ~]# res=`echo 1+1 | bc`\r\n[root@localhost ~]# echo $res\r\n2\r\n \r\n[root@localhost ~]# res=`echo 10 % 3 | bc`\r\n[root@localhost ~]# echo $res\r\n1\r\n \r\n[root@localhost ~]# res=`echo 1.2+1.3|bc`\r\n[root@localhost ~]# echo $res\r\n2.5\r\n \r\n[root@localhost ~]# res=`echo 5.0+3.0|bc`\r\n[root@localhost ~]# echo $res\r\n8.0\r\n \r\n[root@localhost ~]# res=`echo \"scale=2;5.0\/3.0\"|bc`\r\n[root@localhost ~]# echo $res\r\n1.66\r\n \r\n[root@localhost ~]# res=`echo \"scale=2;5.0\/6.0\"|bc`\r\n[root@localhost ~]# echo $res\r\n.83\r\n<\/pre>\n<\/li>\n<li>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<pre>[root@localhost ~]# res=`expr 5 \/ 3`  # \u4e0d\u652f\u6301\u6d6e\u70b9\u8ba1\u7b97\r\n[root@localhost ~]# echo $res\r\n1\r\n \r\n[root@localhost ~]# res=`expr 1+1`  # \u6ce8\u610f\uff1a\u8981\u6709\u7a7a\u683c\r\n[root@localhost ~]# echo $res\r\n1+1\r\n[root@localhost ~]# res=`expr 1 + 1`\r\n[root@localhost ~]# echo $res\r\n2\r\n \r\n\u5982\u679c\u662f\u4e58\u6cd5\uff0c\u5982\u9700\u8981\u8f6c\u4e49\\*\r\n[root@egon ~]# expr 3 \\* 10\r\n30\r\n[root@egon ~]# \r\n<\/pre>\n<\/li>\n<li>3\u3001$(()) \u540cexpr\uff0c\u4e0d\u652f\u6301\u6d6e\u70b9\u6570\u8fd0\u7b97\n<pre><code class=\"language-python\"># \u4f8b\u5982\uff1a\r\n[root@localhost ~]# echo $((1+1))\r\n2\r\n[root@localhost ~]# echo $((1.0+2.0))  # \u4e0d\u652f\u6301\u6d6e\u70b9\u8fd0\u7b97\u7b26\r\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\r\n\r\n# \u6ce8\u610f\uff1a\r\necho $(($num1+$num2))  # \u4e5f\u53ef\u4ee5\u7b80\u5199\u4e3a echo $((num1+num2)) \r\necho $(((5-3)*2))  # \u53ef\u4ee5\u5d4c\u5957\u62ec\u53f7    <\/code><\/pre>\n<\/li>\n<li>4\u3001$[]\u540cexpr\u4ee5\u53ca$(())\uff0c\u4e0d\u652f\u6301\u6d6e\u70b9\u8fd0\u7b97\u200b\n<pre><code class=\"language-python\">[root@egon ~]# echo $[$num1+$num2]  # \u7b49\u540c\u4e8e echo $[num1+num2]\r\n333\r\n[root@egon ~]# echo $[1.3+3.1] \r\n-bash: 1.3+3.1: \u8bed\u6cd5\u9519\u8bef: \u65e0\u6548\u7684\u7b97\u672f\u8fd0\u7b97\u7b26 \uff08\u9519\u8bef\u7b26\u53f7\u662f \".3+3.1\"\uff09<\/code><\/pre>\n<\/li>\n<li>5\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<pre><code class=\"language-python\">[root@localhost ~]# let res=1+1\r\n[root@localhost ~]# echo $res\r\n2\r\n[root@localhost ~]# \r\n[root@localhost ~]# let res=50\/5\r\n[root@localhost ~]# echo $res\r\n10\r\n[root@localhost ~]# let c=1.3*3\r\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>6\u3001\u5f3a\u8c03\uff1a\u6574\u6570\u4e0e\u975e\u6574\u6570\u4e4b\u95f4\u8fd0\u7b97\u4f1a\u62a5\u9519\n<pre><code class=\"language-python\">[root@egon ~]# expr 1 + a\r\nexpr: \u975e\u6574\u6570\u53c2\u6570\r\n[root@egon ~]# expr 1 + 1.3\r\nexpr: \u975e\u6574\u6570\u53c2\u6570<\/code><\/pre>\n<\/li>\n<\/ul>\n<p>\u7ec3\u4e60\u9898<\/p>\n<pre><code class=\"language-python\">#1\u3001\u811a\u672c\u6848\u4f8b: \u7f16\u5199\u5c0f\u811a\u672c, \u53ef\u4ee5\u5b9e\u73b02\u4f4d\u6570\u52a0\u51cf\u4e58\u9664\u8fd0\u7b97\r\n[root@egon shell]# cat a.sh \r\n#!\/bin\/bash\r\n\r\na=$1\r\nb=$2\r\n\r\n[ $# -ne 2 ] &amp;&amp; {\r\n    echo \"\u8bf7\u8f93\u5165\u4e24\u4f4d\u6570\u5b57\u4fe1\u606f\"\r\n    exit\r\n}\r\n\r\necho \"a-b=$((a-b))\"\r\necho \"a+b=$((a+b))\"\r\necho \"a*b=$((a*b))\"\r\necho \"a\/b=$((a\/b))\"\r\n\r\n# 2\u3001\u811a\u672c\u6848\u4f8b: \u7f16\u5199\u5224\u65ad\u8f93\u5165\u53c2\u6570\u662f\u5426\u662f\u6574\u6570\u4fe1\u606f\u811a\u672c\r\n#!\/bin\/bash\r\n\r\na=$1\r\nexpr $a + 0 &amp;&gt;\/dev\/null  # \u53ea\u6709\u6574\u578b\u52a00\u624d\u4e0d\u4f1a\u62a5\u9519\uff0c\u6d6e\u70b9\u6570\u53ca\u5b57\u7b26\u4e0e0\u8be6\u89e3\u90fd\u4f1a\u62a5\u9519\r\n[ $? -eq 0 ] &amp;&amp; echo \"\u8f93\u5165\u7684\u662f\u6574\u6570\u4fe1\u606f\" || echo \"\u8f93\u5165\u7684\u662f\u975e\u6574\u6570\u4fe1\u606f\"\r\n\r\n# 3\u3001\u5982\u4f55\u5229\u7528\u811a\u672c\u8ba1\u7b971+2+3+4..10\u603b\u548c\u6570\u503c\r\n\u65b9\u6cd5\u4e00\uff1a\r\nseq -s \"+\" 10|bc\r\n\r\n\u65b9\u6cd5\u4e8c\uff1a\r\necho {1..10}|tr \" \" \"+\"|bc\r\n\r\n\u65b9\u6cd5\u4e09\uff1a\r\nawk 'BEGIN{for (i=1; i&lt;=10; i++) a=a+i; print a}'<\/code><\/pre>\n<h2>\u4e8c \u6d4b\u8bd5\u8fd0\u7b97\u7b26<\/h2>\n<p>\u6d4b\u8bd5\u547d\u4ee4\uff1atest\uff0c\u8be6\u7ec6\u53ef\u7528man test\u67e5\u8be2<\/p>\n<p>\u6d4b\u8bd5\u7b26\u53f7\uff1a[]\uff0c\u6ce8\u610f\u53ea\u6709\u4e00\u5c42\u4e2d\u62ec\u53f7\uff0c\u4e2d\u62ec\u53f7\u5185\u5de6\u53f3\u4e24\u4fa7\u5fc5\u987b\u8981\u6709\u7a7a\u683c<\/p>\n<p>test\u4e0e[]\u6548\u679c\u90fd\u4e00\u6837\uff0c\u53c2\u6570\u4e5f\u90fd\u4e00\u6837<\/p>\n<h3>2.1 \u6d4b\u8bd5\u6587\u4ef6\u72b6\u6001<\/h3>\n<ul>\n<li>-d \u76ee\u5f55\n<pre><code class=\"language-python\">[root@egon ~]# test -d \/etc\/ ; echo $?\r\n0\r\n\r\n[root@egon ~]# [ -d \/etc ];echo $?  # \u6ce8\u610f[]\u5185\u5de6\u53f3\u4e24\u4fa7\u8981\u6709\u7a7a\u683c\r\n0\r\n\r\nps\uff1a\u4e0b\u9762\u5173\u4e8e[]\u7528\u6cd5\u90fd\u4e0etest\u4e00\u6837\uff0c\u4e0d\u518d\u4e3e\u4f8b<\/code><\/pre>\n<\/li>\n<li>-s \u6587\u4ef6\u957f\u5ea6 &gt; 0\u3001\u975e\u7a7a\n<pre><code class=\"language-python\">[root@egon ~]# touch a.txt\r\n[root@egon ~]# test -s a.txt ;echo $?  # \u6587\u4ef6\u4e3a\u7a7a\u5219\u8fd4\u56de\u5047\r\n1\r\n\r\n[root@egon ~]# test -s \/etc\/passwd ;echo $?  # \u6587\u4ef6\u4e0d\u4e3a\u7a7a\u5219\u8fd4\u56de\u771f\r\n0<\/code><\/pre>\n<\/li>\n<li>-f \u6807\u51c6\u6587\u4ef6\n<pre><code class=\"language-python\">[root@egon ~]# test -f \/etc\/passwd;echo $?\r\n0<\/code><\/pre>\n<\/li>\n<li>-w \u53ef\u5199\n<pre><code class=\"language-python\">[egon@egon ~]$ touch a.txt\r\n[egon@egon ~]$ chmod a-w a.txt\r\n[egon@egon ~]$ [ -w a.txt ];echo $?  # \u8fd4\u56de\u5047\uff0c\u6ce8\u610f\uff0c\u5982\u679c\u662froot\u7528\u6237\uff0c\u65e0\u8bba\u5982\u4f55\u90fd\u6709\u5199\u6743\u9650\r\n1<\/code><\/pre>\n<\/li>\n<li>-r \u53ef\u8bfb\n<pre><code class=\"language-python\">[egon@egon ~]$ ll a.txt \r\n-r--r--r--. 1 egon egon 292 8\u6708  17 21:48 a.txt\r\n[egon@egon ~]$ test -r a.txt;echo $?\r\n0<\/code><\/pre>\n<\/li>\n<li>-x \u53ef\u6267\u884c\n<pre><code class=\"language-python\">[egon@egon ~]$ ll a.txt \r\n-r--r--r--. 1 egon egon 292 8\u6708  17 21:48 a.txt\r\n[egon@egon ~]$ test -x a.txt;echo $?\r\n1<\/code><\/pre>\n<\/li>\n<li>-L \u7b26\u53f7\u8fde\u63a5\n<pre><code class=\"language-python\">[root@egon ~]# ll -d \/lib64\r\nlrwxrwxrwx. 1 root root 9 7\u6708  14 03:33 \/lib64 -&gt; usr\/lib64\r\n[root@egon ~]# test -L \/lib64;echo $?\r\n0<\/code><\/pre>\n<\/li>\n<li>-u \u6587\u4ef6\u6709 suid \u4f4d\u8bbe\u7f6e\n<pre><code class=\"language-python\">[root@egon ~]# ll \/usr\/bin\/passwd \r\n-rwsr-xr-x. 1 root root 27832 6\u6708  10 2014 \/usr\/bin\/passwd\r\n[root@egon ~]# [ -u <code>which passwd<\/code> ];echo $? 0 [root@egon ~]# [ -u <code>which ls<\/code> ];echo $? 1<\/code><\/pre>\n<\/li>\n<\/ul>\n<h3>2.2 \u5b57\u7b26\u4e32\u6d4b\u8bd5<\/h3>\n<ul>\n<li>== \u4e24\u4e2a\u5b57\u7b26\u4e32\u76f8\u7b49\n<pre><code class=\"language-python\">[root@egon ~]# [ \"aaa\" == \"aaa\" ];echo $?\r\n0\r\n\r\n\u6ce8\u610f\uff1a\r\n\u5728 bash \u811a\u672c\u4e2d\uff0ctest \"a\" = \"a\" \u548c test \"a\" == \"a\" \u7684\u6548\u679c\u5b9e\u9645\u4e0a\u662f\u4e00\u6837\u7684\u3002\u5b83\u4eec\u90fd\u662f\u5224\u65ad\u4e24\u4e2a\u5b57\u7b26\u4e32\u662f\u5426\u76f8\u7b49\u3002\r\n= \u662f POSIX \u6807\u51c6\u7684\u5b57\u7b26\u4e32\u6bd4\u8f83\u8fd0\u7b97\u7b26\r\n== \u5728\u8fd9\u91cc\u88ab bash \u6269\u5c55\u652f\u6301\uff0c\u4f5c\u4e3a = \u7684\u7b49\u6548\uff0c\u4e3b\u8981\u662f\u4e3a\u4e86\u548c\u5176\u4ed6\u7f16\u7a0b\u8bed\u8a00\u4fdd\u6301\u4e00\u81f4\u3002\r\n\r\n\u56e0\u6b64\uff0c\u5728 bash \u4e2d = \u548c == \u90fd\u53ef\u4ee5\u7528\u6765\u5224\u65ad\u5b57\u7b26\u4e32\u662f\u5426\u76f8\u7b49\uff0c\r\n\u552f\u4e00\u7684\u533a\u522b\u53ef\u80fd\u5c31\u662f\u5728\u4e00\u4e9b\u8001\u7684\u6216\u8005\u975e bash \u7684 shell \u4e2d\uff0c== \u53ef\u80fd\u4e0d\u88ab\u652f\u6301\u3002\r\n\u6240\u4ee5\uff0c\u5728\u7f16\u5199\u811a\u672c\u65f6\u4e3a\u4e86\u517c\u5bb9\u6027\uff0c\u63a8\u8350\u4f7f\u7528 = \u6765\u8fdb\u884c\u5b57\u7b26\u4e32\u6bd4\u8f83\u3002\r\n<\/code><\/pre>\n<\/li>\n<li>!= \u4e24\u4e2a\u5b57\u7b26\u4e32\u4e0d\u76f8\u7b49\n<pre><code class=\"language-python\">[root@egon ~]# [ \"aaa\" != \"aaa\" ];echo $?\r\n1<\/code><\/pre>\n<\/li>\n<li>-z \u5b57\u7b26\u4e32\u957f\u5ea6\u4e3a\u96f6\n<pre><code class=\"language-python\">[root@egon ~]# ip=\"\"\r\n[root@egon ~]# [ -z \"$ip\" ];echo $?  # \u6ce8\u610f\u5f15\u53f7\r\n0\r\n[root@egon ~]# ip='1.1.1.1'\r\n[root@egon ~]# [ -z \"$ip\" ];echo $?\r\n1<\/code><\/pre>\n<\/li>\n<li>-n \u5b57\u7b26\u4e32\u957f\u5ea6\u4e0d\u4e3a\u96f6\n<pre><code class=\"language-python\">[root@egon ~]# [ -n \"$ip\" ];echo $?  # \u6ce8\u610f\u52a0\u5f15\u53f7\r\n1<\/code><\/pre>\n<\/li>\n<\/ul>\n<h3>2.3 \u6d4b\u8bd5\u6570\u503c<\/h3>\n<p>\u200b test\u4e0e[]\u4e5f\u53ef\u4ee5\u6d4b\u8bd5\u6570\u503c\uff0c\u4e0e [[]]\u548c(())\u6548\u679c\u4e00\u6837\uff0c\u4e0b\u4e00\u5c0f\u8282\u4f1a\u8be6\u7ec6\u4ecb\u7ecd[[]]\u548c(())<\/p>\n<ul>\n<li>-eq \u7b49\u4e8e<\/li>\n<li>-ne \u4e0d\u7b49\u4e8e<\/li>\n<li>-gt \u5927\u4e8e<\/li>\n<li>-lt \u5c0f\u4e8e<\/li>\n<li>-ge \u5927\u4e8e\u7b49\u4e8e<\/li>\n<li>-le \u5c0f\u4e8e\u7b49\u4e8e<\/li>\n<li>-a\u5e76\u4e14<\/li>\n<li>-o\u6216\u8005\n<pre><code class=\"language-python\">[root@egon ~]# [ 10 -eq 10 ];echo $?\r\n0\r\n[root@egon ~]#  [ 10 -eq 10 -a 10 &gt; 3 ];echo $?\r\n0\r\n\r\n# 1\u3001\u793a\u4f8b\uff1a\r\n[root@egon ~]# disk_use=$(df -P |grep '\/$' |awk '{print $5}' |awk -F% '{print $1}')\r\n[root@egon ~]# [ $disk_use -gt 10 ] &amp;&amp; echo \"warn......\"\r\nwarn......\r\n\r\n[root@egon ~]# [ $(id -u) -eq 0 ] &amp;&amp; echo \"\u5f53\u524d\u662f\u8d85\u7ea7\u7528\u6237\" || echo \"you\u4e0d\u662f\u8d85\u7ea7\u7528\u6237\"\r\n\u5f53\u524d\u662f\u8d85\u7ea7\u7528\u6237<\/code><\/pre>\n<\/li>\n<\/ul>\n<h2>\u4e09 \u5173\u7cfb\u8fd0\u7b97\u7b26<\/h2>\n<p>&lt;<\/p>\n<p>&gt;<\/p>\n<p>&lt;=<\/p>\n<p>&gt;=<\/p>\n<p>==<\/p>\n<p>!=<\/p>\n<p>&amp;&amp;<\/p>\n<p>||<\/p>\n<p>\u4e0a\u8ff0\u5173\u7cfb\u8fd0\u7b97\u7b26\u9700\u8981\u914d\u5408(())\u4f7f\u7528(\u6ce8\u610f(())\u5c5e\u4e8eC\u8bed\u8a00\u98ce\u683c\u7684\u6bd4\u8f83)\uff0c\u6700\u7ec8\u90fd\u662f\u7528\u6765\u5f53if\u5224\u65ad\u6216\u8005while\u5faa\u73af\u7684\u6761\u4ef6<\/p>\n<pre><code class=\"language-python\">[root@egon ~]# x=100\r\n\r\n[root@egon ~]# (($x&gt;10))\r\n[root@egon ~]# echo $?\r\n0\r\n\r\n[root@egon ~]# (($x &lt; 10));echo $?\r\n1\r\n\r\n[root@egon ~]# (($x == 100));echo $?\r\n0\r\n\r\n[root@egon ~]# (($x != 100));echo $?\r\n1\r\n\r\n[root@egon ~]# (($x != 100)) &amp;&amp; ((\"egon\" == \"egon\"))\r\n[root@egon ~]# echo $?\r\n1\r\n\r\n[root@egon ~]# (($x != 100)) || ((\"egon\" == \"egon\"))\r\n[root@egon ~]# echo $?\r\n0\r\n\r\n[root@egon ~]# (($x != 100 &amp;&amp; \"egon\" == \"egon\"));echo $?\r\n1\r\n\r\n[root@egon ~]# (($x != 100 || \"egon\" == \"egon\"));echo $?\r\n0\r\n<\/code><\/pre>\n<h2>\u56db \u8d4b\u503c\u8fd0\u7b97\u7b26<\/h2>\n<ul>\n<li>=\n<pre><code class=\"language-python\">[root@egon ~]# x=10\r\n[root@egon ~]# echo $x\r\n10<\/code><\/pre>\n<\/li>\n<li>+=\n<pre><code class=\"language-python\">[root@egon ~]# x=10\r\n[root@egon ~]# ((x%3))\r\n[root@egon ~]# echo $x\r\n10\r\n[root@egon ~]# ((x%=3))\r\n[root@egon ~]# echo $x\r\n1<\/code><\/pre>\n<\/li>\n<li>*=\n<pre><code class=\"language-python\">\u540c\u4e0a<\/code><\/pre>\n<\/li>\n<li>\/=\n<pre><code class=\"language-python\">\u540c\u4e0a<\/code><\/pre>\n<\/li>\n<li>%=\n<pre><code class=\"language-python\">\u540c\u4e0a<\/code><\/pre>\n<\/li>\n<\/ul>\n<h2>\u4e94 \u8865\u5145<\/h2>\n<h3>5.1 \u8865\u5145[[]]<\/h3>\n<p>[[]]\u4e0e[]\u57fa\u672c\u4e00\u6837\uff0c\u4e0d\u540c\u7684\u662f[[]]\u652f\u6301\u6b63\u5219\u5339\u914d\uff0c\u4e0d\u8fc7\u8981\u6ce8\u610f\u7684\u662f\u5fc5\u987b\u5728\u5185\u5c42\u4e2d\u62ec\u53f7\u5185\u5de6\u53f3\u4e24\u4fa7\u52a0\u7a7a\u683c<\/p>\n<pre><code class=\"language-python\">[root@egon ~]# [[ \"$USER\" ==  \"root\" ]];echo $?  # \u6ce8\u610f\u5185\u5c42[]\u4e2d\u5305\u542b\u7684\u5185\u5bb9\u5fc5\u987b\u5de6\u53f3\u4e24\u4fa7\u52a0\u7a7a\u683c\r\n0\r\n[root@egon ~]# [[ \"$USER\" ==  \"root\" ]];echo $?  # \u4e00\u4e2a\u7b49\u53f7\u4e5f\u884c\u4e24\u4e2a\u7b49\u53f7\u4e5f\u53ef\u4ee5\u989d\r\n0\r\n\r\n# \u6b64\u5916[[]]\u5185\u90e8\u662f\u53ef\u4ee5\u4f7f\u7528\u6b63\u5219\u7684,\u6ce8\u610f\uff1a\u6b63\u5219\u8868\u8fbe\u5f0f\u4e0d\u8981\u52a0\u5f15\u53f7\uff01\uff01\uff01\uff01\uff01\uff01\uff01\uff01\uff01\uff01\uff01\r\n[root@egon ~]# [[ \"$USER\" =~ \"^root$\" ]];echo $?  # \u6b63\u5219\u8868\u8fbe\u5f0f\u4e0d\u8981\u52a0\u5f15\u53f7\uff01\uff01\uff01\uff01\uff01\uff01\r\n1\r\n[root@egon ~]# [[ \"$USER\" =~ ^root$ ]];echo $?  # \u6b63\u5219\u8868\u8fbe\u5f0f\u4e0d\u8981\u52a0\u5f15\u53f7\r\n0\r\n[root@egon ~]# [[ ! \"$USER\" =~ t$ ]] &amp;&amp; echo \u6b64\u65f6\u4e0d\u662f\u7ba1\u7406\u5458\u767b\u5f55 || echo \u662f\u7ba1\u7406\u5458\u767b\u5f55\r\n\u662f\u7ba1\u7406\u5458\u767b\u5f55\r\n\r\n[root@egon ~]# num1=123\r\n[root@egon ~]# [[ \"$num1\" =~ ^[0-9]+$ ]];echo $?  # \u5224\u65ad\u662f\u5426\u662f\u6570\u5b57\r\n0\r\n[root@egon ~]# [[ \"$num1\" =~ ^[0-9]+$ ]] &amp;&amp; echo \"\u662f\u6570\u5b57\"\r\n\u662f\u6570\u5b57\r\n\r\n[root@egon ~]# num2=abc123de\r\n[root@egon ~]# [[ \"$num2\" =~ ^[0-9]+$ ]];echo $?\r\n1\r\n[root@egon ~]# [[ \"$num2\" =~ ^[0-9]+$ ]] || echo \"num2\u4e0d\u662f\u6570\u5b57\"\r\nnum2\u4e0d\u662f\u6570\u5b57<\/code><\/pre>\n<p>\u4f01\u4e1a\u9762\u8bd5\u98981: \u4f20\u5165\u4e24\u4e2a\u6570\u503c\u4fe1\u606f, \u81ea\u52a8\u8ba9\u811a\u672c\u663e\u793a\u6570\u503c\u6bd4\u8f83\u60c5\u51b5<\/p>\n<pre><code class=\"language-python\">[root@egon shell]# cat num.sh \r\n#!\/bin\/bash\r\n\r\n[ $# -ne 2 ] &amp;&amp; echo \"\u53ea\u80fd\u4f20\u5165\u4e24\u4e2a\u6574\u6570\" &amp;&amp; exit\r\n[[ ! $1 =~ ^[0-9]+$ ]] &amp;&amp; echo \"\u53c2\u65701\u5fc5\u987b\u662f\u6574\u6570\" &amp;&amp; exit\r\n[[ ! $2 =~ ^[0-9]+$ ]] &amp;&amp; echo \"\u53c2\u65702\u5fc5\u987b\u662f\u6574\u6570\" &amp;&amp; exit\r\n\r\n[[ $1 -lt $2 ]] &amp;&amp; echo \"$1 &lt; $2\"\r\n[[ $1 -gt $2 ]] &amp;&amp; echo \"$1 &gt; $2\"\r\n[[ $1 -eq $2 ]] &amp;&amp; echo \"$1 = $2\"\r\n[root@egon shell]# chmod +x num.sh \r\n[root@egon shell]# .\/num.sh 17 37\r\n17 &lt; 37<\/code><\/pre>\n<h3>5.2 \u8865\u5145\u6d6e\u70b9\u6570\u7684\u6bd4\u8f83<\/h3>\n<pre><code class=\"language-python\"># \u9700\u8981\u6ce8\u610f\u7684\u662f\uff1abc\u7684\u7ed3\u679c\u4e3a1\u4ee3\u8868\u771f\uff0c\u4e3a0\u4ee3\u8868\u5047\r\n[root@egon ~]# echo \"10.3 &gt;= 10.1\" | bc\r\n1\r\n[root@egon ~]# echo \"10.3 != 10.1\" | bc\r\n1\r\n[root@egon ~]# echo \"10.3 != 10.3\" | bc\r\n0\r\n\r\n# \u5e94\u7528\r\n[root@egon ~]# x=10.3\r\n[root@egon ~]# y=10.1\r\n[root@egon ~]# [ `echo \"$x &gt;= $y\" | bc` -eq 1 ] &amp;&amp; echo \"$x \u5927\u4e8e $y\"\r\n10.3 \u5927\u4e8e 10.1<\/code><\/pre>\n<h2>\u516d \u603b\u7ed3<\/h2>\n<p>\u6761\u4ef6\u6d4b\u8bd5\uff1a<\/p>\n<pre><code class=\"language-python\">\u683c\u5f0f1\uff1a test \u6761\u4ef6\u8868\u8fbe\u5f0f\r\n\u683c\u5f0f2\uff1a [ \u6761\u4ef6\u8868\u8fbe\u5f0f ]\r\n\u683c\u5f0f3\uff1a (()) \u6570\u503c\u6bd4\u8f83\uff0c\u8fd0\u7b97  C\u8bed\u8a00\r\n\r\n\u683c\u5f0f4\uff1a [[ \u6761\u4ef6\u8868\u8fbe\u5f0f ]]\uff0c\u652f\u6301\u6b63\u5219  =~<\/code><\/pre>\n<p>\u7ed3\u5408$\u7b26\u53f7<\/p>\n<pre><code class=\"language-python\">$[]    # \u6574\u6570\u8fd0\u7b97\r\n$(())  # \u6574\u6570\u8fd0\u7b97\r\n\r\n$()    # \u53d6\u547d\u4ee4\u7ed3\u679c<\/code><\/pre>\n<p>\u5176\u4ed6<\/p>\n<pre><code class=\"language-python\">()     # \u5b50shell\u4e2d\u6267\u884c<\/code><\/pre>\n<h2>\u4e03 \u5176\u4ed6\u5143\u5b57\u7b26<\/h2>\n<ul>\n<li>1\u3001\u53cd\u5f15\u53f7\u4e0e$()\uff1a\u53d6\u547d\u4ee4\u7684\u7ed3\u679c\n<pre>[root@localhost ~]# echo pwd\r\n\/root \r\n[root@localhost ~]# echo $(pwd) \r\n\/root \r\n\r\n\u4e0d\u4e00\u6837\u7684\u5730\u65b9\u5728\u4e8e$()\u53ef\u4ee5\u5d4c\u5957\uff0c\u800c``\u4e0d\u80fd\u5d4c\u5957 \r\n[root@localhost ~]# echo $(ls $(pwd)) \r\n\r\n# \u7ec3\u4e60 \r\n[root@aliyun test]# touch $(date +%F)_bak.tar.gz \r\n[root@aliyun test]# ls 2020-08-24_bak.tar.gz \r\n<\/pre>\n<\/li>\n<li>2\u3001~\u5bb6\u76ee\u5f55<\/li>\n<li>3\u3001.\u4e0e..<\/li>\n<li>4\u3001!\u8c03\u7528\u5386\u53f2\u547d\u4ee4\u3001\u53d6\u53cd\n<pre><code class=\"language-python\"># 1\u3001\u8c03\u7528\u5386\u53f2\u547d\u4ee4\r\n[root@egon ~]# !1066\r\n[root@egon ~]# !ls  # \u5339\u914d\u6700\u8fd1\u7684\u4e00\u6b21\u5386\u53f2\u547d\u4ee4\r\n\r\n# 2\u3001\u53d6\u53cd1\uff1a\u5bf9\u547d\u4ee4\u7684\u7ed3\u679c\u53d6\u53cd\r\n[root@egon ~]# ! pwd\r\n\/root\r\n[root@egon ~]# echo $?\r\n1\r\n\r\n# 3\u3001\u53d6\u53cd2\uff1a\u6548\u679c\u4e0e^\u96f7\u540c\r\n[root@localhost ~]# touch \/test\/{1.txt,2.txt,a.txt,aaa_bbb.txt}\r\n[root@localhost ~]# find \/test ! -name 1.txt\r\n\/test\r\n\/test\/2.txt\r\n\/test\/a.txt\r\n\/test\/aaa_bbb.txt\r\n\r\n[root@localhost ~]# ls \/test\/[!0-9].txt  # .txt\u524d\u53ea\u6709\u4e00\u4e2a\u5b57\u7b26\uff0c\u4f46\u662f\u975e\u6570\u5b57\r\n\/test\/a.txt\r\n[root@localhost ~]# ls \/test\/[^0-9].txt  # .txt\u524d\u53ea\u6709\u4e00\u4e2a\u5b57\u7b26\uff0c\u4f46\u662f\u975e\u6570\u5b57\r\n\/test\/a.txt\r\n\r\n[root@aliyun test]# ls -a \/etc\/skel\/.[!.]*<\/code><\/pre>\n<\/li>\n<li>5\u3001@\u65e0\u7279\u6b8a\u610f\u4e49<\/li>\n<li>6\u3001#\u6ce8\u91ca<\/li>\n<li>4\u3001$\u53d6\u53d8\u91cf\u503c\n<pre><code class=\"language-python\">[root@localhost ~]# x=1\r\n[root@localhost ~]# echo $x\r\n1<\/code><\/pre>\n<\/li>\n<li>5\u3001%\u3001-\u3001+\u8fd0\u7b97\u7b26\uff0c\u6ce8\u610f%\u53ef\u4ee5\u4e0ejobs\u914d\u5408\u201ckill %\u5de5\u4f5c\u53f7\u201d\u6740\u540e\u53f0\u8fdb\u7a0b\u3002-\u51cf\u53f7\u8fd8\u6709\u533a\u95f4\u53cacd -\u56de\u5230\u4e0a\u4e00\u7ea7\u7684\u610f\u601d\n<pre># \u6570\u5b66\u8fd0\u7b97\r\n# 1\u3001bc\u662f\u6bd4\u8f83\u5e38\u7528\u7684linux\u8ba1\u7b97\u5de5\u5177\u4e86\uff0c\u800c\u4e14\u652f\u6301\u6d6e\u70b9\u8fd0\u7b97\uff1a\r\n[root@localhost ~]# res=echo 1+1 | bc\r\n[root@localhost ~]# echo $res 2 \r\n[root@localhost ~]# res=echo 10 % 3 | bc\r\n[root@localhost ~]# echo $res 1 \r\n[root@localhost ~]# res=echo 1.2+1.3|bc\r\n[root@localhost ~]# echo $res 2.5 \r\n[root@localhost ~]# res=echo 5.0+3.0|bc\r\n[root@localhost ~]# echo $res 8.0 \r\n[root@localhost ~]# res=echo \"scale=2;5.0\/3.0\"|bc\r\n[root@localhost ~]# echo $res 1.66 \r\n[root@localhost ~]# res=echo \"scale=2;5.0\/6.0\"|bc\r\n[root@localhost ~]# echo $res .83 # \r\n\r\n2\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 \r\n[root@localhost ~]# res=expr 5 \/ 3\r\n# \u4e0d\u652f\u6301\u6d6e\u70b9\u8ba1\u7b97 \r\n[root@localhost ~]# echo $res 1 \r\n[root@localhost ~]# res=expr 1+1 # \u6ce8\u610f\uff1a\u8981\u6709\u7a7a\u683c \r\n[root@localhost ~]# echo $res 1+1 \r\n[root@localhost ~]# res=expr 1 + 1\r\n[root@localhost ~]# echo $res 2 \r\n[root@localhost ~]# res=expr 5 \\* 3&lt; # \u5728expr\u4e2d*\u53f7\u8981\u8f6c\u4e49\u624d\u80fd\u7528\uff0c\u5426\u5219\u62a5\u8bed\u6cd5\u9519\u8bef \r\n[root@egon ~]# echo $res 15 \r\n\r\n# 3\u3001$(()) \u540cexpr\uff0c\u4e0d\u652f\u6301\u6d6e\u70b9\u6570\u8fd0\u7b97 \r\n[root@localhost ~]# echo $((1+1)) \r\n2 \r\n[root@localhost ~]# echo $((1.0+2.0)) \r\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 \r\n\r\n# 4\u3001$[]\u540cexpr\u4ee5\u53ca$(())\uff0c\u4e0d\u652f\u6301\u6d6e\u70b9\u8fd0\u7b97 \r\n[root@localhost ~]# x=1 \r\n[root@localhost ~]# echo $[$x+1] 2 \r\n\r\n# 5\u3001let \u4e0d\u652f\u6301\u6d6e\u70b9\u6570\u8fd0\u7b97\uff0c\u800c\u4e14\u4e0d\u652f\u6301\u76f4\u63a5\u8f93\u51fa\uff0c\u53ea\u80fd\u8d4b\u503c \r\n[root@localhost ~]# let res=1+1 \r\n[root@localhost ~]# echo $res 2 \r\n[root@localhost ~]# \r\n[root@localhost ~]# let res=50\/5 \r\n[root@localhost ~]# echo $res 10 \r\n[root@localhost ~]# let c=1.3*3 \r\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\" \r\n[root@aliyun test]# x=1 \r\n[root@aliyun test]# let x+=10 \r\n[root@aliyun test]# echo $x 11\r\n<\/pre>\n<\/li>\n<li>6\u3001^\u540c!\u4e00\u6837<\/li>\n<li>7\u3001&amp;\u540e\u53f0\u8fd0\u884c\n<pre><code class=\"language-python\">[root@localhost home]# echo \"hello\";sleep 3;echo \"world\" &amp;<\/code><\/pre>\n<\/li>\n<li>8\u3001*\u4efb\u610f\u591a\u4e2a\u5b57\u7b26\n<pre><code class=\"language-python\">[root@localhost ~]# touch 1.txt 2.txt aa.txt aaa.txt\r\n[root@localhost ~]# rm -rf *.txt\r\n[root@localhost ~]# touch 1.txt 2.txt aa.txt aaa.txt a1c.txt\r\n[root@localhost ~]# ls *.txt\r\n1.txt  2.txt  a1c.txt  aaa.txt  aa.txt<\/code><\/pre>\n<\/li>\n<li>9\u3001()\u5728\u5b50shell\u4e2d\u6267\u884c\n<pre><code class=\"language-python\">[root@localhost ~]# (x=1)\r\n[root@localhost ~]# echo $x\r\n\r\n\u5e94\u7528\r\n[root@localhost ~]# (umask 066;touch a.txt)  # umask\u7684\u8bbe\u7f6e\u53ea\u5728\u5b50shell\u4e2d\u6709\u6548\r\n[root@localhost ~]# ll a.txt \r\n-rw-------. 1 root root 0 8\u6708  13 15:22 a.txt\r\n[root@localhost ~]# touch b.txt\r\n[root@localhost ~]# ll b.txt \r\n-rw-r--r--. 1 root root 0 8\u6708  13 15:23 b.txt<\/code><\/pre>\n<\/li>\n<li>10\u3001_\u4e0b\u5212\u7ebf\uff1a\u65e0\u7279\u6b8a\u610f\u4e49\uff0c\u53ef\u4ee5\u7528\u4e8e\u540d\u5b57\u7684\u58f0\u660e\n<pre><code class=\"language-python\">[root@localhost ~]# tar -czvf  <code>date +%F_%H:%M:%S<\/code>_bak.tar.gz \/etc\/<\/code><\/pre>\n<\/li>\n<li>11\u3001=\u8d4b\u503c\uff0c==\u5224\u65ad\u76f8\u7b49\u6027\n<pre><code class=\"language-python\">[root@localhost ~]# [ 1 == 1 ]  # \u6761\u4ef61 == 1\u7684\u5de6\u53f3\u4e24\u8fb9\u5fc5\u987b\u6709\u7a7a\u683c\r\n[root@localhost ~]# echo $?    # \u5224\u65ad\u4e0a\u4e00\u6761\u547d\u4ee4\u7684\u7ed3\u679c\u662f\u5426\u4e3a\u771f\uff0c0=\u300btrue\r\n0<\/code><\/pre>\n<\/li>\n<li>12\u3001|\u7ba1\u9053\uff1a\u628a\u4e00\u4e2a\u8fdb\u7a0b\u7684\u5904\u7406\u7ed3\u679c\u4f20\u9012\u7ed9\u53e6\u5916\u4e00\u4e2a\u8fdb\u7a0b\n<pre><code class=\"language-python\">[root@localhost ~]# ps aux | grep python\r\n\r\n|\u7ba1\u9053\u547d\u4ee4\u7684\u4f5c\u7528\uff0c\u662f\u5c06\u5de6\u4fa7\u547d\u4ee4\u7684\u6807\u51c6\u8f93\u51fa\u8f6c\u6362\u4e3a\u6807\u51c6\u8f93\u5165\uff0c\u63d0\u4f9b\u7ed9\u53f3\u4fa7\u547d\u4ee4\u4f5c\u4e3a\u53c2\u6570\u3002\u4f46\u662f\uff0c\u5927\u591a\u6570\u547d\u4ee4\u90fd\u4e0d\u63a5\u53d7\u6807\u51c6\u8f93\u5165\u4f5c\u4e3a\u53c2\u6570\uff0c\u53ea\u80fd\u76f4\u63a5\u5728\u547d\u4ee4\u884c\u8f93\u5165\u53c2\u6570\uff0c\u8fd9\u5bfc\u81f4\u65e0\u6cd5\u7528\u7ba1\u9053\u547d\u4ee4\u4f20\u9012\u53c2\u6570\u3002\u6bd4\u5982echo\u547d\u4ee4\u5c31\u4e0d\u63a5\u53d7\u7ba1\u9053\u4f20\u53c2\u3002\r\n$ echo \"hello world\" | echo\r\nxargs\u547d\u4ee4\u7684\u4f5c\u7528\uff0c\u662f\u5c06\u6807\u51c6\u8f93\u5165\u8f6c\u4e3a\u547d\u4ee4\u884c\u53c2\u6570\uff0c\u4f8b\u5982\r\n$ echo \"hello world\" | xargs echo\r\nhello world\r\n\r\n[root@localhost ~]# find \/home\/ -type d -name \"test*\" |xargs ls\r\n1.txt  2.txt  3.txt\r\n[root@localhost ~]# ls \/home\/test\r\n1.txt  2.txt  3.txt<\/code><\/pre>\n<\/li>\n<li>13\u3001\\\u8f6c\u4e49\u7279\u6b8a\u5b57\u7b26\n<pre><code class=\"language-python\">[root@localhost ~]# mkdir a\\ b.txt  # \u867d\u7136\u53ef\u4ee5\uff0c\u4f46\u4e0d\u63a8\u8350\r\n[root@localhost ~]# ll\r\n\u603b\u7528\u91cf 0\r\ndrwxr-xr-x. 2 root root 6 8\u6708  13 15:35 a b.txt\r\n\r\n[root@localhost ~]# echo $RMB  # \u9ed8\u8ba4\u4f1a\u5f53\u6210\u53d8\u91cf\r\n\r\n[root@localhost ~]# echo '$RMB'  # \u53d6\u6d88\u7279\u6b8a\u610f\u4e49\r\n$RMB\r\n[root@localhost ~]# echo \\$RMB  # \u53d6\u6d88\u7279\u6b8a\u610f\u4e49\r\n$RMB<\/code><\/pre>\n<\/li>\n<li>14\u3001[]\u6761\u4ef6\u6d4b\u8bd5\uff0c\u540e\u7eed\u4f1a\u8be6\u7ec6\u4ecb\u7ecd\n<pre><code class=\"language-python\">[root@localhost ~]# name=\"egon\"\r\n[root@localhost ~]# [ $name == \"egon\" ];echo $?\r\n0\r\n[root@localhost ~]# name=\"adf\"\r\n[root@localhost ~]# [ $name == \"egon\" ];echo $?\r\n1\r\n\r\n[root@localhost ~]# [ -d \/test ];echo $?\r\n0\r\n[root@localhost ~]#<\/code><\/pre>\n<\/li>\n<li>15\u3001\u5f15\u53f7\n<pre><code class=\"language-python\">''  \u5f3a\u5f15\u7528\uff08\u5728\u5355\u5f15\u53f7\u4e2d\u90fd\u89c6\u4e3a\u666e\u901a\u5b57\u7b26\uff09\r\n\" \" \u5f31\u5f15\u7528 \uff08\u5728\u53cc\u5f15\u53f7\u4e2d\u4fdd\u7559\u53d8\u91cf\uff09\r\n\r\n[root@localhost ~]# x=111\r\n[root@localhost ~]# echo \"$x\"\r\n111\r\n[root@localhost ~]# echo '$x'\r\n$x\r\n[roo<\/code><\/pre>\n<\/li>\n<li>16\u3001;\u4e0e&amp;&amp;\u4e0e||\u8fde\u63a5\u591a\u6761\u547d\u4ee4\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\r\nbash: gagaga: \u672a\u627e\u5230\u547d\u4ee4...\r\negon\r\n[root@localhost home]# gagaga &amp;&amp; ls  # \u53ea\u6709\u524d\u4e00\u6761\u547d\u4ee4\u6267\u884c\u6210\u529f\uff0c\u624d\u4f1a\u6267\u884c\u540e\u7eed\u547d\u4ee4\r\nbash: gagaga: \u672a\u627e\u5230\u547d\u4ee4...\r\n\r\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\r\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>17\u3001:\u7a7a\u547d\u4ee4\uff0c\u771f\u503c\n<pre><code class=\"language-python\">[root@egon ~]# :\r\n[root@egon ~]# echo $?\r\n0<\/code><\/pre>\n<\/li>\n<li>18\u3001\/\u8def\u5f84\u5206\u9694\u7b26<\/li>\n<li>19\u3001{}\u5faa\u73af\u5217\u8868\n<pre><code class=\"language-python\">[root@localhost home]# touch \/test\/{0..9}.txt\r\n[root@localhost home]# ls \/test\/\r\n0.txt  1.txt  2.txt  3.txt  4.txt  5.txt  6.txt  7.txt  8.txt  9.txt\r\n\r\n[root@localhost ~]# touch {1..3}{a..d}.txt\r\n[root@localhost ~]# ls\r\n1a.txt 1b.txt 1c.txt 1d.txt 2a.txt 2b.txt 2c.txt 2d.txt 3a.txt 3b.txt 3c.txt 3d.txt\r\n\r\n[root@egon ~]# x=100\r\n[root@egon ~]# echo ${x}%  # \u63a7\u5236\u53d8\u91cf\u540d\u7684\u8303\u56f4\r\n100%\r\n[root@egon ~]# \r\n[root@egon ~]# echo $xrmb\r\n\r\n[root@egon ~]# echo ${x}rmb\r\n100rmb<\/code><\/pre>\n<\/li>\n<li>20\u3001\u91cd\u5b9a\u5411\n<pre><code class=\"language-python\">&gt; &gt;&gt; \u8f93\u51fa\u91cd\u5b9a\u5411\r\n&lt; &lt;&lt; \u8f93\u5165\u91cd\u5b9a\u5411 &gt; \u8986\u76d6  &gt;&gt; \u8ffd\u52a0\r\n[root@localhost home]# cat &gt;&gt; a.txt &lt;&lt; EOF &gt; 111\r\n&gt; 222\r\n&gt; 333\r\n&gt; EOF\r\n\r\n0\u6807\u51c6\u8f93\u5165\u30011\u6807\u51c6\u6b63\u786e\u8f93\u51fa\u30012\u6807\u51c6\u9519\u8bef\u8f93\u51fa\uff0c&amp;\u6807\u51c6\u6b63\u786e\u548c\u9519\u8bef\u8f93\u51fa\r\n[root@localhost home]# pwd 1&gt;a.txt\r\n[root@localhost home]# cat a.txt \r\n\/home\r\n[root@localhost home]# gagag 2&gt;a.txt\r\n[root@localhost home]# cat a.txt \r\nbash: gagag: \u672a\u627e\u5230\u547d\u4ee4...\r\n[root@localhost home]# gagaga &amp;&gt;\/dev\/null\r\n\r\n&lt; &lt;&lt; \u8f93\u5165\u91cd\u5b9a\u5411\r\n[root@localhost ~]# mysql -uroot -p123 &lt; bbs.sql\r\n[root@localhost home]# grep root &lt; \/etc\/passwd\r\nroot:x:0:0:root:\/root:\/bin\/bash\r\noperator:x:11:0:operator:\/root:\/sbin\/nologin\r\n\r\n[root@localhost home]# dd if=\/dev\/zero of=\/a.txt bs=1M count=10\r\n\u8bb0\u5f55\u4e8610+0 \u7684\u8bfb\u5165\r\n\u8bb0\u5f55\u4e8610+0 \u7684\u5199\u51fa\r\n10485760\u5b57\u8282(10 MB)\u5df2\u590d\u5236\uff0c0.024387 \u79d2\uff0c430 MB\/\u79d2\r\n[root@localhost home]# dd &lt;\/dev\/zero &gt;\/b.txt bs=1M count=10\r\n\u8bb0\u5f55\u4e8610+0 \u7684\u8bfb\u5165\r\n\u8bb0\u5f55\u4e8610+0 \u7684\u5199\u51fa\r\n10485760\u5b57\u8282(10 MB)\u5df2\u590d\u5236\uff0c0.0202365 \u79d2\uff0c518 MB\/\u79d2\r\n\r\n[root@localhost home]# ll \/a.txt \r\n-rw-r--r--. 1 root root 10485760 8\u6708  13 16:02 \/a.txt\r\n[root@localhost home]# ll \/b.txt \r\n-rw-r--r--. 1 root root 10485760 8\u6708  13 16:03 \/b.txt<\/code><\/pre>\n<\/li>\n<li>21\u3001?\u4efb\u610f\u4e00\u4e2a\u5b57\u7b26\n<pre><code class=\"language-python\">[root@localhost ~]# ls ??.txt\r\naa.txt\r\n[root@localhost ~]# ls a?c.txt\r\na1c.txt\r\n[root@localhost ~]# rm -rf *.txt<\/code><\/pre>\n<\/li>\n<li>22\u3001\u8303\u56f4\u4e2d\u7684\u4efb\u610f\u4e00\u4e2a\u5b57\u7b26 [12] [ac] [a-z] [0-9]\n<pre><code class=\"language-python\">[root@localhost ~]# touch a1c a2c axc aXc axd\r\n[root@localhost ~]# ls a?c\r\na1c  a2c  axc  aXc\r\n[root@localhost ~]# ls a[1x]c\r\na1c  axc\r\n[root@localhost ~]# ls a[a-z]c\r\naxc  aXc\r\n[root@localhost ~]# ls a[A-Z]c  # \u4e0d\u533a\u5206\u5927\u5c0f\u5199\r\naxc  aXc\r\n[root@localhost ~]# ls a[x]c\r\naxc\r\n[root@localhost ~]# ls a[X]c\r\naXc\r\n[root@localhost ~]# ls a[0-9]c\r\na1c  a2c\r\n[root@localhost ~]# ls \/dev\/sd[a-z]*\r\n\/dev\/sda  \/dev\/sda1  \/dev\/sda2  \/dev\/sda3  \/dev\/sdb1<\/code><\/pre>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u5143\u5b57\u7b26 \u5143\u5b57\u7b26\u6307\u7684\u662f\u80fd\u591f\u88abshell\u89e3\u91ca\u7684\u7279\u6b8a\u5b57\u7b26\uff0c\u6bcf\u4e2a\u7279\u6b8a\u5b57\u7b26\u90fd\u6709\u5176\u7279\u6b8a\u542b\u4e49\uff0c\u8fd9\u4e9b\u5b57\u7b26\u4e00\u65b9\u9762\u53ef\u7528\u4e8e\u53d8\u91cf\u503c\u7684\u8fd0 [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[64],"tags":[21,19,75,22,20],"_links":{"self":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts\/391"}],"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=391"}],"version-history":[{"count":9,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts\/391\/revisions"}],"predecessor-version":[{"id":10834,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts\/391\/revisions\/10834"}],"wp:attachment":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=391"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=391"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=391"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}