{"id":296,"date":"2016-11-03T22:12:47","date_gmt":"2016-11-03T14:12:47","guid":{"rendered":"http:\/\/blog.haostudio.net\/hwp\/?p=296"},"modified":"2017-07-25T00:05:11","modified_gmt":"2017-07-24T16:05:11","slug":"shell-tips-%e5%b0%87%e5%91%bd%e4%bb%a4%e5%88%97%e4%b9%8b%e5%8f%83%e6%95%b8%e8%bd%89%e6%8f%9b%e6%88%90-shell-%e5%85%a7%e9%83%a8%e7%9a%84%e8%ae%8a%e6%95%b8","status":"publish","type":"post","link":"https:\/\/blog.haostudio.net\/hwp\/shell-tips-%e5%b0%87%e5%91%bd%e4%bb%a4%e5%88%97%e4%b9%8b%e5%8f%83%e6%95%b8%e8%bd%89%e6%8f%9b%e6%88%90-shell-%e5%85%a7%e9%83%a8%e7%9a%84%e8%ae%8a%e6%95%b8\/","title":{"rendered":"[Shell Tips]  \u5c07\u547d\u4ee4\u5217\u4e4b\u53c3\u6578\u8f49\u63db\u6210 shell \u5167\u90e8\u7684\u8b8a\u6578"},"content":{"rendered":"<!--more-->\n<h3>\u5c07\u547d\u4ee4\u5217\u4e4b\u53c3\u6578\u8f49\u63db\u6210 shell \u5167\u90e8\u7684\u8b8a\u6578<\/h3>\n<pre><code>$ cat test.sh\n## Script parameters handling\nfor i in &quot;$@&quot;; do\n    if [[ $i == *=* ]]; then\n        parameter=${i%%=*}\n        value=${i##*=}\n        echo &quot;Command line: setting $parameter to ${value:-(empty)}&quot;\n        eval $parameter=$value\n    fi\ndone\n\n$ test.sh KERNEL=new COLOR=red Loop=3 DEFAULT_VAR=\n\u5247\u5728 test.sh \u7d93\u904e\u4e0a\u9762\u7684for-loop \u4e4b\u5f8c, \u5c31\u6703\u7522\u751f4\u500b\u8b8a\u6578\u5206\u5225\u70ba:\nKERNEL=new \nCOLOR=red \nLoop=3 \nDEFAULT_VAR=\n<\/code><\/pre>\n<p>\u53c3\u8003\u4f86\u6e90: <a href=\"https:\/\/github.com\/igorpecovnik\/lib\">Armbian<\/a><\/p>","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[89],"tags":[61],"class_list":["post-296","post","type-post","status-publish","format-standard","hentry","category-shell-script","tag-shell-script"],"_links":{"self":[{"href":"https:\/\/blog.haostudio.net\/hwp\/wp-json\/wp\/v2\/posts\/296","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.haostudio.net\/hwp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.haostudio.net\/hwp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.haostudio.net\/hwp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.haostudio.net\/hwp\/wp-json\/wp\/v2\/comments?post=296"}],"version-history":[{"count":2,"href":"https:\/\/blog.haostudio.net\/hwp\/wp-json\/wp\/v2\/posts\/296\/revisions"}],"predecessor-version":[{"id":382,"href":"https:\/\/blog.haostudio.net\/hwp\/wp-json\/wp\/v2\/posts\/296\/revisions\/382"}],"wp:attachment":[{"href":"https:\/\/blog.haostudio.net\/hwp\/wp-json\/wp\/v2\/media?parent=296"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.haostudio.net\/hwp\/wp-json\/wp\/v2\/categories?post=296"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.haostudio.net\/hwp\/wp-json\/wp\/v2\/tags?post=296"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}