{"id":248,"date":"2014-06-29T09:53:48","date_gmt":"2014-06-29T09:53:48","guid":{"rendered":"http:\/\/ixyzero.com\/blog\/?p=248"},"modified":"2014-06-29T09:53:48","modified_gmt":"2014-06-29T09:53:48","slug":"shell%e8%84%9a%e6%9c%ac%e4%b8%ad%e5%b8%b8%e7%94%a8%e7%9a%84%e6%8e%a7%e5%88%b6%e7%bb%93%e6%9e%84-shell%e5%be%aa%e7%8e%af","status":"publish","type":"post","link":"https:\/\/ixyzero.com\/blog\/archives\/248.html","title":{"rendered":"SHELL\u811a\u672c\u4e2d\u5e38\u7528\u7684\u63a7\u5236\u7ed3\u6784 &amp; Shell\u5faa\u73af"},"content":{"rendered":"<p>\u4ece\u7f51\u4e0a\u6536\u96c6\u800c\u6765\uff0c\u81ea\u5df1\u5b66\u4e60\u7684\u540c\u65f6\u4e5f\u53ef\u4ee5\u4f5c\u4e3a\u4e00\u4e2a\u5907\u4efd\u4ee5\u4f9b\u968f\u65f6\u53c2\u8003\uff1a<\/p>\n<hr \/>\n<h6>if &#8230; then\u8bed\u53e5<\/h6>\n<div id=\"article_content\" class=\"article_content\" style=\"color: #000000;\">\n<pre class=\"lang:default decode:true\">if [ test_command ]\nthen\ncommands\nfi<\/pre>\n<h6>if &#8230; then &#8230; else\u8bed\u53e5<\/h6>\n<pre class=\"lang:default decode:true\">if [ test_command ]\nthen\n  commands\nelse\n  commands\nfi<\/pre>\n<h6>if &#8230; then &#8230; elif &#8230; (else)\u8bed\u53e5<\/h6>\n<div>\n<pre class=\"lang:default decode:true\">if [ test_command ]\nthen\n  commands\nelif [ test_command ]\nthen\n  commands\n...\n...\nelse (optional)\n  commands\nfi<\/pre>\n<\/div>\n<h6>for &#8230; in\u8bed\u53e5<\/h6>\n<div>\n<pre class=\"lang:default decode:true\">for \u53d8\u91cf in\u00a0\u53d8\u91cf\u5217\u8868\ndo\n  commands\ndone<\/pre>\n<\/div>\n<h6>while\u8bed\u53e5<\/h6>\n<div>\n<pre class=\"lang:default decode:true\">while \u6761\u4ef6\u4e3a\u771f\ndo\n  commands\ndone<\/pre>\n<\/div>\n<div>\n<h6>until\u8bed\u53e5<\/h6>\n<\/div>\n<div>\n<pre class=\"lang:default decode:true\">until \u6761\u4ef6\u4e3a\u771f\ndo\n  commands\ndone<\/pre>\n<\/div>\n<div>\n<h6>case\u8bed\u53e5<\/h6>\n<\/div>\n<div>\n<pre class=\"lang:default decode:true\">case $variable in\nmatch_1)\ncommands_to_execute_for_1\n;;\nmatch_2)\ncommands_to_execute_for_2\n;;\nmatch_3)\ncommands_to_execute_for_3\n;;\n...\n...\n*) (\u53ef\u9009 - any other value)\ncommands_to_execute_for_no_match\n;;\nesac<\/pre>\n<\/div>\n<div style=\"color: gray;\"><small><small>\u6765\u6e90\uff1a\u00a0&lt;<a href=\"http:\/\/blog.csdn.net\/jubincn\/article\/details\/7288632\" target=\"_blank\">http:\/\/blog.csdn.net\/jubincn\/article\/details\/7288632<\/a><small>&gt;<\/small><\/small><\/small><\/p>\n<hr \/>\n<\/div>\n<\/div>\n<h5 style=\"color: #000000;\">Shell\u5faa\u73af<\/h5>\n<div style=\"color: #000000;\">\n<p style=\"color: #333333;\">#<strong><span style=\"color: #ff0000;\">\u6570\u5b57\u6bb5\u5f62\u5f0f<br \/>\n<\/span><\/strong>for i in {1..10}<br \/>\ndo<br \/>\necho $i<br \/>\ndone<\/p>\n<p style=\"color: #333333;\">#<strong><span style=\"color: #ff0000;\">\u8be6\u7ec6\u5217\u51fa\uff08\u5b57\u7b26\u4e14\u9879\u6570\u4e0d\u591a\uff09<\/span><\/strong><br \/>\nfor File in 1 2 3 4 5<br \/>\ndo<br \/>\necho $File<br \/>\ndone<\/p>\n<p style=\"color: #333333;\">#<strong><span style=\"color: #ff0000;\">\u5bf9\u5b58\u5728\u7684\u6587\u4ef6\u8fdb\u884c\u5faa\u73af<br \/>\n<\/span><\/strong>for shname in `ls *.sh`<br \/>\ndo<br \/>\nname=`echo &#8220;$shname&#8221; | awk -F. &#8216;{print $1}&#8217;`<br \/>\necho $name<br \/>\ndone<\/p>\n<p style=\"color: #333333;\">#<strong><span style=\"color: #ff0000;\">\u67e5\u627e\u5faa\u73af\uff08ls\u6570\u636e\u91cf\u592a\u5927\u7684\u65f6\u5019\u4e5f\u53ef\u4ee5\u7528\u8fd9\u79cd\u65b9\u6cd5\uff09<br \/>\n<\/span><\/strong>for shname in `find . -type f -name &#8220;*.sh&#8221;`<br \/>\ndo<br \/>\nname=`echo &#8220;$shname&#8221; | awk -F\/ &#8216;{print $2}&#8217;`<br \/>\necho $name<br \/>\ndone<\/p>\n<p style=\"color: #333333;\">#<strong><span style=\"color: #ff0000;\">(())\u8bed\u6cd5\u5faa\u73af<\/span><\/strong>&#8211;\u6709\u70b9\u50cfC\u8bed\u6cd5\uff0c\u4f46\u8bb0\u5f97\u53cc\u62ec\u53f7<br \/>\nfor((i=1;i&lt;100;i++))<br \/>\ndo<br \/>\nif((i%3==0))<br \/>\nthen<br \/>\necho $i<br \/>\ncontinue<br \/>\nfi<br \/>\ndone<\/p>\n<p style=\"color: #333333;\">#<strong><span style=\"color: #ff0000;\">seq\u5f62\u5f0f \u8d77\u59cb\u4ece1\u5f00\u59cb<br \/>\n<\/span><\/strong>for i in `seq 100`<br \/>\ndo<br \/>\nif((i%3==0))<br \/>\nthen<br \/>\necho $i<br \/>\ncontinue<br \/>\nfi<br \/>\ndone<\/p>\n<p style=\"color: #333333;\">#<strong><span style=\"color: #ff0000;\">while\u5faa\u73af\u6ce8\u610f\u4e3a\u65b9\u62ec\u53f7[]\uff0c\u4e14\u6ce8\u610f\u7a7a\u683c<\/span><\/strong><br \/>\nmin=1<br \/>\nmax=100<br \/>\nwhile [ $min -le $max ]<br \/>\ndo<br \/>\necho $min<br \/>\nmin=`expr $min + 1`<br \/>\ndone<\/p>\n<p style=\"color: #333333;\">#<strong><span style=\"color: #ff0000;\">\u53cc\u62ec\u53f7\u5f62\u5f0f\uff0c\u5185\u90e8\u7ed3\u6784\u6709\u70b9\u50cfC\u7684\u8bed\u6cd5\uff0c\u6ce8\u610f\u8d4b\u503c\uff1ai=$(($i+1))<br \/>\n<\/span><\/strong>i=1<br \/>\nwhile(($i&lt;100))<br \/>\ndo<br \/>\nif(($i%4==0))<br \/>\nthen<br \/>\necho $i<br \/>\nfi<br \/>\ni=$(($i+1))<br \/>\ndone<\/p>\n<hr \/>\n<p style=\"color: #333333;\">\n<h6 style=\"color: #333333;\">\u6574\u4f53\u793a\u4f8b\u5982\u4e0b\uff1a<\/h6>\n<pre class=\"lang:default decode:true \">#!\/bin\/bash\n\nfor((i=0; i&lt;10; i++));do\n\techo $(expr $i * 4)\ndone\n\nfor i in $(seq 10);do\n\techo $i\ndone\n\ni=1\nwhile(($i&lt;10));do\n\techo $i\n\ti=`expr $i + 1`\ndone\n\nfor i in {1..10};do\n\techo $i\ndone\n\nfor i in {01..10};do\n\techo $i\ndone\n\nfor i in {a..z};do\n\techo $i\ndone\n\nfor i in $(ls);do\n\techo $i\ndone\n\nfor i in `ls`;do\n\techo $i\ndone\n\nfor i in f1 f2 f3;do\n\techo $i\ndone\n\ncat \/tmp\/drops.txt | while read url title\ndo\n    title=$(echo $title | tr ' &lt;\/' '_')\n    curl -s $url | sed -n '\/&lt;div id=\"content\"&gt;\/,\/entry-tags\/p' &gt;\/tmp\/tmp.html\n    cat \/tmp\/top.html \/tmp\/tmp.html \/tmp\/bottom.html &gt;\/tmp\/$title.html\ndone\n\nwhile read url title\ndo\n    title=$(echo $title | tr ' &lt;\/' '_')\n    curl -s $url | sed -n '\/&lt;div id=\"content\"&gt;\/,\/entry-tags\/p' &gt;\/tmp\/tmp.html\n    cat \/tmp\/top.html \/tmp\/tmp.html \/tmp\/bottom.html &gt;\/tmp\/$title.html\ndone &lt; \/tmp\/drops.txt\n\n####\ndir=(papers tips tools news web pentesting database binary)\ndir_num=${#dir[@]}\nfor((i=0;i&lt;$dir_num;i++))\ndo\n\tfor j in $(seq 1 15)\n\tdo\n\tif [ \"$j\" == 1 ]\n\tthen\n\t\techo http:\/\/drops.wooyun.org\/category\/${dir[i]}\n\telse\n\t\techo http:\/\/drops.wooyun.org\/category\/${dir[i]}\/page\/$j\n\tfi\n\tdone\ndone\n####\n\narr=(\"a\" \"b\" \"c\")\necho \"arr is (${arr[@]})\"\n\narr=(a b c)\nfor i in ${arr[@]}\ndo\n\techo $i\ndone\n\n\necho \"\u53c2\u6570,$*\u8868\u793a\u811a\u672c\u8f93\u5165\u7684\u6240\u6709\u53c2\u6570\uff1a\"\nfor i in $* ; do\n\techo $i\ndone\n\nEGREP=\/bin\/egrep\nCOUNTRY=('cn' 'hk' 'tw')\nfor c in ${COUNTRY[@]}\ndo\n    wget \"http:\/\/www.ipdeny.com\/ipblocks\/data\/countries\/$c.zone\"\n    country_file=$c.zone\n    IPS=$($EGREP -v \"^#|^$\" $country_file)\n    for ip in $IPS\n    do\n        echo \"blocking $ip\"\n        iptables -A INPUT -s $ip -j DROP\n    done\ndone\n\n# SHELL\u6570\u7ec4\u8be6\u89e3\n# http:\/\/ixyzero.com\/blog\/archives\/178.html\n$ A=(a b c def)\n\n$ echo ${A[@]}\t\t#\u53d6\u5168\u90e8\u5143\u7d20\na b c def\n\n$ echo ${A[0]}\t\t#\u53d6\u7b2c\u4e00\u4e2a\u5143\u7d20\na\n\n$ echo ${#A[@]}\t\t#\u53d6\u5f97\u6570\u7ec4\u5143\u7d20\u7684\u4e2a\u6570\n4\n\n$ echo ${#A[3]}\t\t#\u53d6\u5f97\u7b2c4\u4e2a\u5143\u7d20\u7684\u957f\u5ea6\n3<\/pre>\n<p>&nbsp;<\/p>\n<h6 style=\"color: #333333;\">\u62d3\u5c55\u94fe\u63a5\uff1a<\/h6>\n<ul>\n<li style=\"color: #333333;\"><a title=\"Linux\u4e2d\u7684shell\u5faa\u73af\" href=\"http:\/\/ixyzero.com\/blog\/archives\/210.html\" target=\"_blank\">Linux\u4e2d\u7684shell\u5faa\u73af<\/a><\/li>\n<li style=\"color: #333333;\"><a title=\"Linux\u7684shell\u7f16\u5199\u2013for\/while\u5faa\u73af\" href=\"http:\/\/ixyzero.com\/blog\/archives\/406.html\" target=\"_blank\">Linux\u7684shell\u7f16\u5199\u2013for\/while\u5faa\u73af<\/a><\/li>\n<\/ul>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u4ece\u7f51\u4e0a\u6536\u96c6\u800c\u6765\uff0c\u81ea\u5df1\u5b66\u4e60\u7684\u540c\u65f6\u4e5f\u53ef\u4ee5\u4f5c\u4e3a\u4e00\u4e2a\u5907\u4efd\u4ee5\u4f9b\u968f\u65f6\u53c2\u8003\uff1a if &#8230; then\u8bed\u53e5 if [  [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[65],"class_list":["post-248","post","type-post","status-publish","format-standard","hentry","category-linux","tag-shell"],"views":2549,"_links":{"self":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/248","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\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/comments?post=248"}],"version-history":[{"count":0,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/248\/revisions"}],"wp:attachment":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/media?parent=248"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/categories?post=248"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/tags?post=248"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}