{"id":2317,"date":"2011-01-24T20:25:32","date_gmt":"2011-01-24T12:25:32","guid":{"rendered":"http:\/\/edsionte.com\/techblog\/?p=2317"},"modified":"2011-01-25T16:58:42","modified_gmt":"2011-01-25T08:58:42","slug":"shell%e7%bc%96%e7%a8%8b%e4%b8%ad%e7%9a%84%e5%bc%95%e7%94%a8","status":"publish","type":"post","link":"http:\/\/edsionte.com\/techblog\/archives\/2317","title":{"rendered":"shell\u7f16\u7a0b\u4e2d\u7684\u5f15\u7528"},"content":{"rendered":"<p>shell\u7f16\u7a0b\u8bed\u8a00\u4e2d\u6709\u56db\u79cd\u5f15\u7528\u7b26\u53f7\uff0c\u5206\u522b\u662f\u5355\u5f15\u53f7(&#8221;)\uff0c\u53cc\u5f15\u53f7(&#8220;&#8221;)\uff0c\u53cd\u5355\u5f15\u53f7(&#8220;)\u548c\u53cd\u659c\u6760\u3002\u524d\u4e09\u79cd\u7b26\u53f7\u5fc5\u987b\u6210\u5bf9\u51fa\u73b0\u6765\u4f7f\u7528\uff0c\u800c\u540e\u8005\u5219\u5355\u72ec\u4f7f\u7528\u3002\u6709\u65f6\u5019\u6211\u4eec\u9700\u8981shell\u5c06\u67d0\u4e9b\u5b57\u7b26\u8fdb\u884c\u7279\u6b8a\u89e3\u91ca\uff0c\u6b64\u65f6\u5f15\u7528\u7b26\u53f7\u5c31\u6d3e\u4e0a\u4e86\u7528\u573a\u3002<\/p>\n<h4>\u5355\u5f15\u53f7<\/h4>\n<p><strong>1.\u6574\u4f53\u8d4b\u503c<\/strong><\/p>\n<p>\u5728\u5bf9\u53d8\u91cf\u8fdb\u884c\u8d4b\u503c\u65f6\uff0c\u4f7f\u7528\u5355\u5f15\u53f7\u5c06\u4e2d\u95f4\u6709\u7a7a\u683c\u7684\u5b57\u7b26\u5f15\u7528\u540e\u8d4b\u503c\u7ed9\u53d8\u91cf\u540e\uff0cshell\u4f1a\u5c06\u8fd9\u4e9b\u5b57\u7b26\u770b\u4f5c\u6210\u4e00\u4e2a\u6574\u4f53\u6765\u5904\u7406\u3002\u6bd4\u5982\uff0c\u6211\u4eec\u9700\u8981\u5728name\u6587\u4ef6\u4e2d\u67e5\u627eedsionte wu\u8fd9\u4e2a\u59d3\u540d\uff1a<\/p>\n<pre class=\"brush:c\">edsionte@edsionte-desktop:~\/shelltest$ cat name\r\nedsionte\r\nzhanyu\r\nmiao\r\nedsionte wu\r\nedsionteli\r\nedsionte@edsionte-desktop:~\/shelltest$ grep edsionte wu name\r\ngrep: wu: \u6ca1\u6709\u90a3\u4e2a\u6587\u4ef6\u6216\u76ee\u5f55\r\nname:edsionte\r\nname:edsionte wu\r\nname:edsionteli<\/pre>\n<p>\u6b64\u65f6grep\u547d\u4ee4\u4ea7\u751f\u4e86\u9519\u8bef\u4fe1\u606f\u3002\u7531\u4e8eedsionte\u548cwu\u5b57\u7b26\u4e4b\u95f4\u6709\u7a7a\u683c\uff0cgrep\u5c06edsionte\u89c6\u4e3a\u8981\u67e5\u627e\u7684\u5b57\u7b26\uff0c\u800cwu\u548cname\u90fd\u662f\u6240\u8981\u67e5\u627e\u7684\u6587\u4ef6\u3002\u5982\u679c\u6211\u4eec\u5c06edsionte\u548cwu\u653e\u5165\u5355\u5f15\u53f7\u5185\uff0c\u5c31\u53ef\u4ee5\u6b63\u786e\u5f97\u5230\u7ed3\u679c\uff1a<\/p>\n<pre class=\"brush:c\">edsionte@edsionte-desktop:~\/shelltest$ grep 'edsionte wu' name\r\nedsionte wu<\/pre>\n<p>\u901a\u8fc7\u4f7f\u7528\u5355\u5f15\u53f7\uff0cshell\u4ece\u4e0a\u9762\u7684\u90a3\u6761\u547d\u4ee4\u4e2d\u63d0\u53d6\u5230edsionte wu\u548cname\u4e24\u4e2a\u53c2\u6570\uff0c\u518d\u5c06\u8fd9\u4e24\u4e2a\u53c2\u6570\u4f20\u9012\u7ed9grep\u547d\u4ee4\u3002<\/p>\n<p><strong>2.\u4fdd\u7559\u5b57\u7b26<\/strong><\/p>\n<p>\u4f7f\u7528\u5355\u5f15\u53f7\u5c06\u5b57\u7b26\u5f15\u7528\u540e\uff0cshell\u4f1a\u539f\u5c01\u4e0d\u52a8\u7684\u4fdd\u7559\u5355\u5f15\u53f7\u5185\u7684\u5b57\u7b26\uff0c\u6bd4\u5982\uff1a<\/p>\n<pre class=\"brush:c\">edsionte@edsionte-desktop:~\/shelltest$ echo edsionte              wu\r\nedsionte wu\r\nedsionte@edsionte-desktop:~\/shelltest$ echo 'edsionte              wu'\r\nedsionte              wu<\/pre>\n<p>\u4e0d\u4f7f\u7528\u5355\u5f15\u53f7\u65f6\uff0cshell\u4f1a\u5c06\u5b57\u7b26\u4e4b\u95f4\u7684\u591a\u4e2a\u7a7a\u683c\u7f29\u51cf\u81f3\u4e00\u4e2a\uff1b\u5982\u679c\u4f7f\u7528\u4e86\u5355\u5f15\u53f7\uff0c\u90a3\u4e48shell\u4f1a\u539f\u5c01\u4e0d\u52a8\u5c06\u5355\u5f15\u53f7\u4e2d\u7684\u5185\u5bb9\u63d0\u53d6\u51fa\u6765\uff0c\u9001\u81f3echo\u547d\u4ee4\u3002  \u540c\u6837\uff0c\u7531\u4e8e\u5355\u5f15\u53f7\u539f\u5c01\u4e0d\u52a8\u7684\u7279\u6027\uff0c\u5904\u4e8e\u5355\u5f15\u53f7\u5185\u90e8\u7684\u7279\u6b8a\u5b57\u7b26\u4e0d\u4f1a\u88abshell\u89e3\u91ca\u3002\u6bd4\u5982\uff1a<\/p>\n<pre class=\"brush:c\">edsionte@edsionte-desktop:~\/shelltest$ ls\r\ngender  name  number\r\nedsionte@edsionte-desktop:~\/shelltest$ echo *\r\ngender name number\r\nedsionte@edsionte-desktop:~\/shelltest$ echo '*'\r\n*<\/pre>\n<p>\u53ef\u4ee5\u770b\u5230\uff0c\u7279\u6b8a\u5b57\u7b26*\u5e76\u4e0d\u4f1a\u88ab\u5355\u5f15\u53f7\u6240\u89e3\u91ca\u3002\u63a5\u4e0b\u6765\u7684\u8fd9\u4e2a\u4f8b\u5b50\u4f1a\u8ba9\u4f60\u66f4\u6df1\u5165\u7684\u7406\u89e3\u4e0a\u8ff0\u4e24\u4e2a\u529f\u80fd\u3002\u6bd4\u5982\uff1a<\/p>\n<pre class=\"brush:c\">edsionte@edsionte-desktop:~\/shelltest$ files='I have these files: *'\r\nedsionte@edsionte-desktop:~\/shelltest$ echo $files\r\nI have these files: gender name number<\/pre>\n<p>\u53ef\u80fd\u4f60\u4f1a\u6709\u7591\u95ee\uff1a\u5904\u4e8e\u5355\u5f15\u53f7\u5185\u7684*\u4e3a\u4ec0\u4e48\u4f1a\u88abshell\u89e3\u91ca\u5462\uff1f\u5982\u679c\u4f60\u7406\u89e3\u4e86\u8fd9\u91cc\u7684\u5355\u5f15\u53f7\u6240\u8d77\u7684\u4f5c\u7528\u5c31\u56de\u6d88\u9664\u4e0a\u9762\u7684\u7591\u60d1\u3002\u5bf9\u4e8eecho $files\u547d\u4ee4\u6765\u8bf4\uff0cshell\u4f1a\u5148\u5c06$file\u66ff\u6362\u4e3aI have these files: *\uff0c\u4e5f\u5c31\u662f\u8bf4\u8fd9\u91cc\u7684\u5355\u5f15\u53f7\u662f\u4e3a\u4e86\u5c06\u4e0a\u8ff0\u5b57\u7b26\u6574\u4f53\u8d4b\u503c\u7ed9files\u53d8\u91cf\uff1b\u7136\u540eshell\u4f1a\u5c06*\u66ff\u6362\u4e3a\u5f53\u524d\u76ee\u5f55\u4e0b\u7684\u6240\u6709\u6587\u4ef6\u540d\uff1b\u6700\u540e\u5c06I have these files: gender name number\u4f5c\u4e3a\u4e00\u4e2a\u6574\u4f53\u4f20\u7ed9echo\u547d\u4ee4\u3002<\/p>\n<h4>\u53cc\u5f15\u53f7<\/h4>\n<p>\u53cc\u5f15\u53f7\u548c\u5355\u5f15\u53f7\u7684\u529f\u80fd\u51e0\u4e4e\u76f8\u540c\uff0c\u53ea\u4e0d\u8fc7\u53cc\u5f15\u53f7\u5bf9\u4e2a\u522b\u51e0\u4e2a\u7279\u6b8a\u5b57\u7b26\u4f1a\u505a\u89e3\u91ca\uff0c\u800c\u4e0d\u50cf\u5355\u5f15\u53f7\u90a3\u6837\u5b8c\u5168\u5ffd\u7565\u6240\u6709\u7279\u6b8a\u5b57\u7b26\u3002\u8fd9\u51e0\u4e2a\u7279\u6b8a\u5b57\u7b26\u4e3a\uff1a\u7f8e\u5143\u7b26\u53f7($)\uff0c\u53cd\u5f15\u53f7(&#8220;)\uff0c\u53cd\u659c\u6760(\/)\u3002\u6bd4\u5982\uff1a<\/p>\n<pre class=\"brush:c\">edsionte@edsionte-laptop:~\/shelltest$ ls\r\ninfo  name  nf  status  test  whos\r\nedsionte@edsionte-laptop:~\/shelltest$ x=*\r\nedsionte@edsionte-laptop:~\/shelltest$ echo $x\r\ninfo name nf status test whos\r\nedsionte@edsionte-laptop:~\/shelltest$ echo '$x'\r\n$x\r\nedsionte@edsionte-laptop:~\/shelltest$ echo \"$x\"\r\n*<\/pre>\n<p>\u53ef\u4ee5\u770b\u5230\uff0cshell\u5bf9\u4f4d\u4e8e\u53cc\u5f15\u53f7\u5185\u7684$\u8fdb\u884c\u4e86\u89e3\u91ca\uff0c\u4e5f\u5c31\u662f\u5c06\u5176\u89e3\u91ca\u4e3a\u5bf9x\u53d8\u91cf\u7684\u5f15\u7528\u3002\u9664\u6b64\u4e4b\u5916\uff0c\u53cc\u5f15\u53f7\u548c\u5355\u5f15\u53f7\u5e76\u65e0\u592a\u5927\u5dee\u5f02\u3002\u6bd4\u5982\uff1a<\/p>\n<pre class=\"brush:c\">edsionte@edsionte-laptop:~\/shelltest$ x=\"edsionte    wu\"\r\nedsionte@edsionte-laptop:~\/shelltest$ echo $x\r\nedsionte wu\r\nedsionte@edsionte-laptop:~\/shelltest$ echo \"$x\"\r\nedsionte    wu\r\nedsionte@edsionte-laptop:~\/shelltest$ echo '$x'\r\n$x<\/pre>\n<p>\u5bf9\u4e8e\u7b2c\u4e00\u6761\u7684\u8d4b\u503c\u8bed\u53e5\uff0c\u4e0d\u7ba1\u4f7f\u7528\u5355\u5f15\u53f7\u8fd8\u662f\u53cc\u5f15\u53f7\uff0c\u6548\u679c\u662f\u4e00\u6837\u7684\uff0c\u90fd\u662f\u5c06edsionte    wu\u4f5c\u4e3a\u4e00\u4e2a\u6574\u4f53\u8d4b\u503c\u7ed9\u53d8\u91cfx\u3002<\/p>\n<h4>\u53cd\u5f15\u53f7<\/h4>\n<p>\u5728\u547d\u4ee4A\u4e2d\u4f7f\u7528\u53cd\u5f15\u53f7\u7684\u76ee\u7684\u5e76\u4e0d\u662f\u5e0c\u671bshell\u4fdd\u7559\u67d0\u4e9b\u7279\u6b8a\u5b57\u7b26\u7684\u672c\u610f\uff0c\u800c\u662f\u5c06\u5176\u4ed6\u7684\u547d\u4ee4B\u5305\u542b\u8d77\u6765\uff0c\u5e76\u628a\u547d\u4ee4B\u7684\u8f93\u51fa\u63d2\u5165\u5230\u547d\u4ee4B\u6240\u5728\u7684\u4f4d\u7f6e\u3002\u5176\u683c\u5f0f\u4e3a\uff1a<br \/>\ncmdA  `cmdB`<\/p>\n<pre class=\"brush:c\">\u6bd4\u5982\u901a\u8fc7\u53cd\u5f15\u53f7\u7684\u5f15\u7528\u5728echo\u547d\u4ee4\u4e2d\u4f7f\u7528date\u547d\u4ee4\uff1a\r\nedsionte@edsionte-desktop:~\/shelltest$ echo 'Now is `date`'\r\nNow is `date`\r\nedsionte@edsionte-desktop:~\/shelltest$ echo \"Now is `date`\"\r\nNow is 2011\u5e74 01\u6708 25\u65e5 \u661f\u671f\u4e8c 16:48:40 CST<\/pre>\n<p>\u7531\u4e8e\u5355\u5f15\u53f7\u5bf9\u4efb\u4f55\u5b57\u7b26\u90fd\u4e0d\u4f5c\u7279\u6b8a\u89e3\u91ca\uff0c\u56e0\u6b64\u53cd\u5f15\u53f7\u5728\u5355\u5f15\u53f7\u4e2d\u5e76\u4e0d\u8d77\u4f5c\u7528\u3002\u4f46\u662f\u5728\u53cc\u5f15\u53f7\u4e2d\uff0c\u53cd\u5f15\u53f7\u4e2d\u7684date\u547d\u4ee4\u88abshell\u89e3\u91ca\u4e86\u3002<br \/>\n\u7531\u4e8e\u53cc\u5f15\u53f7<\/p>\n<h4>\u53cd\u659c\u6760<\/h4>\n<p><strong>1.\u6d88\u9664\u7279\u6b8a\u542b\u4e49<\/strong><\/p>\n<p>\u5982\u679c\u5728\u4e00\u4e9b\u7279\u6b8a\u5b57\u7b26\u524d\u9762\u52a0\u4e0a\u53cd\u659c\u6760\uff0c\u5219\u4f1a\u6d88\u9664\u8fd9\u4e9b\u5b57\u7b26\u7684\u7279\u6b8a\u542b\u4e49\u3002\u56e0\u6b64\\c\u7684\u529f\u6548\u76f8\u5f53\u4e8e&#8217;c&#8217;\u3002\u6bd4\u5982\uff1a<\/p>\n<pre class=\"brush:c\">edsionte@edsionte-desktop:~\/shelltest$ x=*\r\nedsionte@edsionte-desktop:~\/shelltest$ echo $x\r\ngender name number\r\nedsionte@edsionte-desktop:~\/shelltest$ echo \\$x\r\n$x<\/pre>\n<p>\u53ef\u4ee5\u770b\u5230\uff0c\u5728$\u524d\u9762\u52a0\u5165\u53cd\u659c\u6760\u53ef\u4ee5\u53bb\u9664$\u7684\u5f15\u7528\u542b\u4e49\u800c\u5c06$\u672c\u8eab\u663e\u793a\u51fa\u6765\u3002<\/p>\n<p><span style=\"font-size: 11.6667px;\"><strong>2.\u7eed\u884c<\/strong><\/span><\/p>\n<p>\u5f53\u53cd\u659c\u6760\u4f4d\u4e8e\u4e00\u884c\u7684\u6700\u540e\u4e00\u4e2a\u5b57\u7b26\u65f6\uff0c\u5b83\u4f1a\u8d77\u5230\u7eed\u884c\u7684\u4f5c\u7528\u3002\u6bd4\u5982\uff1a<\/p>\n<pre class=\"brush:c\">edsionte@edsionte-desktop:~\/shelltest$ file=edsion\\\r\n&gt; te\r\nedsionte@edsionte-desktop:~\/shelltest$ echo $file\r\nedsionte<\/pre>\n<p>\u4f7f\u7528\u53cd\u659c\u6760\u8fdb\u884c\u7eed\u884c\u540e\uff0c\u53cd\u659c\u6760\u524d\u540e\u7684\u5b57\u7b26\u4e4b\u95f4\u5e76\u6ca1\u6709\u5206\u9694\u7b26\u3002<\/p>\n<p><strong>3.\u5728\u53cc\u5f15\u53f7\u4e2d\u4f7f\u7528 \u53cd\u659c\u6760<\/strong><\/p>\n<p>\u5982\u679c\u6211\u4eec\u5e0c\u671bshell\u4fdd\u7559\u53cc\u5f15\u53f7\u4e2d\u7684\u7279\u6b8a\u5b57\u7b26\uff08\u5373$\u3001&#8220;\u548c\\\uff09\u7684\u542b\u4e49\uff0c\u90a3\u4e48\u53cd\u659c\u6760\u5c31\u6d3e\u4e0a\u4e86\u7528\u573a\u3002\u6bd4\u5982\uff1a<\/p>\n<pre class=\"brush:c\">edsionte@edsionte-desktop:~\/shelltest$ x=5\r\nedsionte@edsionte-desktop:~\/shelltest$ echo \"The value of \\$x is $x\"\r\nThe value of $x is 5<\/pre>\n<p>end<\/p>\n","protected":false},"excerpt":{"rendered":"<p>shell\u7f16\u7a0b\u8bed\u8a00\u4e2d\u6709\u56db\u79cd\u5f15\u7528\u7b26\u53f7\uff0c\u5206\u522b\u662f\u5355\u5f15\u53f7(&#8221;)\uff0c\u53cc\u5f15\u53f7(&#8220;&#8221;)\uff0c\u53cd [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[153],"tags":[155,125],"class_list":["post-2317","post","type-post","status-publish","format-standard","hentry","category-shell","tag-shell","tag-linux"],"views":4998,"_links":{"self":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/posts\/2317","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/comments?post=2317"}],"version-history":[{"count":0,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/posts\/2317\/revisions"}],"wp:attachment":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/media?parent=2317"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/categories?post=2317"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/tags?post=2317"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}