{"id":3646,"date":"2017-10-28T13:37:08","date_gmt":"2017-10-28T05:37:08","guid":{"rendered":"https:\/\/ixyzero.com\/blog\/?p=3646"},"modified":"2017-10-28T13:37:08","modified_gmt":"2017-10-28T05:37:08","slug":"bash%e4%b8%ad%e5%a6%82%e4%bd%95%e5%88%a4%e6%96%ad%e5%ad%97%e7%ac%a6%e4%b8%b2%e6%98%af%e5%90%a6%e4%bb%a5%e6%9f%90%e4%b8%aa%e5%ad%97%e7%ac%a6%e4%b8%b2%e5%bc%80%e5%a4%b4%e3%80%81%e5%8c%85%e5%90%ab","status":"publish","type":"post","link":"https:\/\/ixyzero.com\/blog\/archives\/3646.html","title":{"rendered":"Bash\u4e2d\u5982\u4f55\u5224\u65ad\u5b57\u7b26\u4e32\u662f\u5426\u4ee5\u67d0\u4e2a\u5b57\u7b26(\u4e32)\u5f00\u5934\u3001\u5305\u542b\u3001\u7ed3\u5c3e\uff1f"},"content":{"rendered":"<p>=Start=<\/p>\n<h4>\u7f18\u7531\uff1a<\/h4>\n<p>\u6700\u8fd1\u5728\u5199\u4e00\u4e9b\u529f\u80fd\u6027\u811a\u672c\uff0c\u53d1\u73b0Bash\u4e2d\u5b57\u7b26\u4e32\u7684startwith\/endwith\/contain\u5224\u65ad\u8fd9\u4e9b\u529f\u80fd\u8fd8\u662f\u6bd4\u8f83\u5e38\u7528\u7684\uff0c\u4f46Bash\u4e0d\u50cfPython\u81ea\u5e26\u8fd9\u4e9b\u51fd\u6570\uff0c\u6240\u4ee5\u9700\u8981\u81ea\u5df1\u6574\u7406\u603b\u7ed3\u4e00\u4e0b\uff0c\u65b9\u4fbf\u4ee5\u540e\u4f7f\u7528\u3002<\/p>\n<h4>\u6b63\u6587\uff1a<\/h4>\n<h5>\u53c2\u8003\u89e3\u7b54\uff1a<\/h5>\n<p>\u4e3b\u8981\u53c2\u8003\u4e4b\u524d\u8bb0\u5f55\u7684\u6587\u7ae0\uff1a<\/p>\n<ul>\n<li><a href=\"https:\/\/ixyzero.com\/blog\/archives\/512.html\">LINUX SHELL\u811a\u672c\u7684\u5b57\u7b26\u4e32\u622a\u53d6\u7b49\u64cd\u4f5c<\/a><\/li>\n<li><a href=\"https:\/\/ixyzero.com\/blog\/archives\/1225.html\">SHELL\u6761\u4ef6\u6d4b\u8bd5<\/a><\/li>\n<\/ul>\n<p>&amp;<\/p>\n<ul>\n<li>\u5b57\u7b26\u4e32\u7684\u5224\u7b49\u5e94\u8be5\u4f7f\u7528\u300c=\u300d\u6216\u300c==\u300d\u7b26\u53f7\uff1b<\/li>\n<li>\u6570\u5b57\u7684\u5224\u7b49\u624d\u662f\u4f7f\u7528\u300c-eq\u300d\u6765\u8fdb\u884c\uff08\u7f51\u4e0a\u5f88\u591a\u6587\u7ae0\u778e\u5199\uff0c\u4e5f\u4e0d\u9a8c\u8bc1\u4e00\u4e0b\u2026\u2026\uff09\uff1b<\/li>\n<\/ul>\n<pre class=\"lang:default decode:true \">#!\/bin\/bash\r\n# set -x\r\n\r\nvar=\"ixyzero.com is the best!\"\r\n\r\nfunction func_main() {\r\n\t# if [ $# -gt 0 ]; then\r\n\t# \tinput=\"$1\"\r\n\t# else\r\n\t# \tinput=\"ixyzero.com\"\r\n\t# fi\r\n\tinput=${1:-\"ixyzero.com\"}\r\n\techo $input\r\n\t\r\n\t# echo ${#input}\t# ${#input} \u662f $input \u53d8\u91cf\u7684\u957f\u5ea6\r\n\tif [ ${var:0:${#input}} = $input ]; then\r\n\t\techo \"\\\"$var\\\" startwith $input\"\r\n\telse\r\n\t\techo \"\\\"$var\\\" not startwith $input\"\r\n\tfi\r\n}\r\nfunc_main \"$@\"<\/pre>\n<p>=<\/p>\n<pre class=\"lang:default decode:true\"># \u6d4b\u8bd5\/\u4f7f\u7528\u65b9\u6cd5\u5982\u4e0b\r\n#\u4e0d\u5e26\u53c2\u6570\uff08\u4f7f\u7528\u9ed8\u8ba4\u503c\u8fdb\u884c\u6d4b\u8bd5\uff09\r\n$ bash sh_str_startwith.sh\r\nixyzero.com\r\n\"ixyzero.com is the best!\" startwith ixyzero.com\r\n$\r\n#\u4e3b\u52a8\u4f20\u5165\u53c2\u65701\r\n$ bash sh_str_startwith.sh abc\r\nabc\r\n\"ixyzero.com is the best!\" not startwith abc\r\n#\u4e3b\u52a8\u4f20\u5165\u53c2\u65702\r\n$ bash sh_str_startwith.sh i\r\ni\r\n\"ixyzero.com is the best!\" startwith i<\/pre>\n<p>&amp;<\/p>\n<pre class=\"lang:default decode:true \">#!\/bin\/bash\r\n# set -x\r\n\r\nvar=\"ixyzero.com is the best!\"\r\n\r\nfunction func_main() {\r\n\t# if [ $# -gt 0 ]; then\r\n\t# \tinput=\"$1\"\r\n\t# else\r\n\t# \tinput=\"ixyzero.com\"\r\n\t# fi\r\n\tinput=${1:-\"best!\"}\r\n\techo $input\r\n\t\r\n\t# echo ${#input}\t# ${#input} \u662f $input \u53d8\u91cf\u7684\u957f\u5ea6\r\n\tif [ ${var:0-${#input}} = $input ]; then\r\n\t\techo \"\\\"$var\\\" endwith $input\"\r\n\telse\r\n\t\techo \"\\\"$var\\\" not endwith $input\"\r\n\tfi\r\n}\r\nfunc_main \"$@\"<\/pre>\n<p>=<\/p>\n<pre class=\"lang:default decode:true \">$ bash sh_str_endwith.sh\r\nbest!\r\n\"ixyzero.com is the best!\" endwith best!\r\n$\r\n$ bash sh_str_endwith.sh best\r\nbest\r\n\"ixyzero.com is the best!\" not endwith best\r\n$\r\n$ bash sh_str_endwith.sh !\r\n!\r\n\"ixyzero.com is the best!\" endwith !\r\n$<\/pre>\n<p>&amp;<\/p>\n<pre class=\"lang:default decode:true\"># \u5b57\u7b26\u4e32\u5305\u542b\u5224\u65ad\r\n# returns OK if $1 contains $2\r\nstrstr() {\r\n  [ \"${1#*$2*}\" = \"$1\" ] &amp;&amp; return 1\r\n  return 0\r\n}<\/pre>\n<h5>\u53c2\u8003\u94fe\u63a5\uff1a<\/h5>\n<ul>\n<li>Linux Shell\u811a\u672c\u7684\u5b57\u7b26\u4e32\u622a\u53d6\u7b49\u64cd\u4f5c<br \/>\n<a href=\"https:\/\/ixyzero.com\/blog\/archives\/512.html\">https:\/\/ixyzero.com\/blog\/archives\/512.html<\/a><\/li>\n<li>Shell\u6761\u4ef6\u6d4b\u8bd5<br \/>\n<a href=\"https:\/\/ixyzero.com\/blog\/archives\/1225.html\">https:\/\/ixyzero.com\/blog\/archives\/1225.html<\/a><\/li>\n<\/ul>\n<p>=END=<\/p>\n","protected":false},"excerpt":{"rendered":"<p>=Start= \u7f18\u7531\uff1a \u6700\u8fd1\u5728\u5199\u4e00\u4e9b\u529f\u80fd\u6027\u811a\u672c\uff0c\u53d1\u73b0Bash\u4e2d\u5b57\u7b26\u4e32\u7684startwith\/endwith\/co [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23,11,7],"tags":[83,958,957],"class_list":["post-3646","post","type-post","status-publish","format-standard","hentry","category-knowledgebase-2","category-linux","category-programing","tag-bash","tag-endwith","tag-startwith"],"views":15979,"_links":{"self":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/3646","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/comments?post=3646"}],"version-history":[{"count":1,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/3646\/revisions"}],"predecessor-version":[{"id":3647,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/3646\/revisions\/3647"}],"wp:attachment":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/media?parent=3646"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/categories?post=3646"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/tags?post=3646"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}