{"id":703,"date":"2019-04-25T11:37:48","date_gmt":"2019-04-25T03:37:48","guid":{"rendered":"https:\/\/www.linuxcool.com\/?p=703"},"modified":"2019-04-26T12:29:26","modified_gmt":"2019-04-26T04:29:26","slug":"expr","status":"publish","type":"post","link":"https:\/\/www.linuxcool.com\/expr","title":{"rendered":"expr\u547d\u4ee4 – \u547d\u4ee4\u884c\u8ba1\u6570\u5668"},"content":{"rendered":"\n

expr\u547d\u4ee4\u7684\u82f1\u6587\u5168\u79f0\u662f\u201cexpression\u201d\uff0c\u5373\u662f\u8868\u8fbe\u5f0f\u7684\u610f\u601d\uff0c\u4f5c\u7528\u662f\u4e00\u4e2a\u547d\u4ee4\u884c\u7684\u8ba1\u6570\u5668\uff0c\u5e38\u7528\u4e8e\u5728UNIX\/LINUX\u7cfb\u7edf\u4e2d\u6c42\u8868\u8fbe\u5f0f\u53d8\u91cf\u7684\u503c\uff0c\u4e00\u822c\u7528\u4e8e\u6574\u6570\u503c\uff0c\u4e5f\u53ef\u7528\u4e8e\u5b57\u7b26\u4e32\u3002 <\/p>\n\n\n\n

\u8bed\u6cd5\u683c\u5f0f\uff1a<\/strong>expr [\u8868\u8fbe\u5f0f]<\/p>\n\n\n\n

\u5e38\u7528\u53c2\u6570\uff1a<\/strong><\/p>\n\n\n\n
\u7a7a\u683c<\/td>\u9694\u5f00\u6bcf\u4e2a\u9879 <\/td><\/tr>
\\\uff08\u53cd\u659c\u6760\uff09<\/td>\u653e\u5728 shell \u7279\u5b9a\u7684\u5b57\u7b26\u524d\u9762 <\/td><\/tr>
“”(\u5f15\u53f7)<\/td>\u5bf9\u5305\u542b\u7a7a\u683c\u548c\u5176\u4ed6\u7279\u6b8a\u5b57\u7b26\u7684\u5b57\u7b26\u4e32\u8981\u7528\u5f15\u53f7\u62ec\u8d77\u6765 <\/td><\/tr><\/tbody><\/table>\n\n\n\n

\u53c2\u8003\u5b9e\u4f8b<\/strong><\/p>\n\n\n\n

\u8ba1\u7b97\u5b57\u4e32\u957f\u5ea6\uff1a<\/p>\n\n\n\n

[root@linuxcool ~]# expr length \u201cthis is a test\u201d  
14
<\/pre>\n\n\n\n

\u6293\u53d6\u5b57\u4e32\uff1a <\/p>\n\n\n\n

[root@linuxcool ~]# expr substr \u201cthis is a test\u201d 3 5 
is is<\/pre>\n\n\n\n

\u6293\u53d6\u7b2c\u4e00\u4e2a\u5b57\u7b26\u6570\u5b57\u4e32\u51fa\u73b0\u7684\u4f4d\u7f6e\uff1a<\/p>\n\n\n\n

[root@linuxcool ~]# expr index \"sarasara\" a 
2<\/pre>\n\n\n\n

\u6574\u6570\u8fd0\u7b97\uff1a<\/p>\n\n\n\n

[root@linuxcool ~]# expr 14 % 9
5
[root@linuxcool ~]# expr 10 + 10
20
[root@linuxcool ~]# expr 1000 + 900
1900
[root@linuxcool ~]# expr 30 \/ 3 \/ 2
5
[root@linuxcool ~]# expr 30 * 3
expr: Syntax error
[root@linuxcool ~]# expr 30 \/* 3
90
<\/pre>\n\n\n\n

\u6ce8\u610f\uff1a\u4f7f\u7528\u4e58\u53f7\u65f6\uff0c\u5fc5\u987b\u7528\u53cd\u659c\u7ebf\u5c4f\u853d\u5176\u7279\u5b9a\u542b\u4e49\u3002\u56e0\u4e3ashell\u53ef\u80fd\u4f1a\u8bef\u89e3\u663e\u793a\u661f\u53f7\u7684\u610f\u4e49<\/p>\n\n\n\n

\u4f7f\u7528expr\u8fdb\u884c\u56db\u5219\u8fd0\u7b97\uff1a<\/p>\n\n\n\n

[root@linuxcool ~]# expr \\( 10 + 10 \\) \\* 2 + 100 
140<\/pre>\n","protected":false},"excerpt":{"rendered":"

expr\u547d\u4ee4\u7684\u82f1\u6587\u5168\u79f0\u662f\u201cexpression\u201d\uff0c\u5373\u662f\u8868\u8fbe\u5f0f\u7684\u610f\u601d\uff0c\u4f5c\u7528\u662f\u4e00\u4e2a\u547d\u4ee4\u884c\u7684\u8ba1\u6570\u5668\uff0c\u5e38\u7528\u4e8e\u5728UNIX […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[],"_links":{"self":[{"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/posts\/703"}],"collection":[{"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/comments?post=703"}],"version-history":[{"count":9,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/posts\/703\/revisions"}],"predecessor-version":[{"id":1342,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/posts\/703\/revisions\/1342"}],"wp:attachment":[{"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/media?parent=703"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/categories?post=703"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/tags?post=703"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}