{"id":406,"date":"2014-07-05T03:48:23","date_gmt":"2014-07-05T03:48:23","guid":{"rendered":"http:\/\/ixyzero.com\/blog\/?p=406"},"modified":"2014-07-05T03:48:23","modified_gmt":"2014-07-05T03:48:23","slug":"linux%e7%9a%84shell%e7%bc%96%e5%86%99-for%e5%be%aa%e7%8e%af","status":"publish","type":"post","link":"https:\/\/ixyzero.com\/blog\/archives\/406.html","title":{"rendered":"\u7528shell\u7f16\u5199for\/while\u5faa\u73af"},"content":{"rendered":"<p>\u56e0\u4e3a\u5728\u7f16\u5199shell\u7684\u65f6\u5019for\u5faa\u73af\u662f\u4e2a\u6bd4\u8f83\u91cd\u8981\u7684\u8bed\u6cd5\u7ed3\u6784\uff0c\u7ecf\u5e38\u4f1a\u78b0\u5230\u6240\u4ee5\u60f3\u53ca\u65f6\u505a\u4e2a\u603b\u7ed3\/\u5907\u5fd8\uff0c\u65b9\u4fbf\u4ee5\u540e\u67e5\u9605\uff1a<\/p>\n<h6>x.\u5faa\u73af\u8bfb\u53d6\u6587\u4ef6\u6bcf\u4e00\u4e2a\u975e\u7a7a\u884c\u7684\u5185\u5bb9<\/h6>\n<pre class=\"lang:default decode:true  \">GITDIR=\"$HOME\/git_s\"\nmkdir -p $GITDIR\n\ncd $GITDIR\nwhile read p; do\n    if [ -n \"$p\" ]; then\n        echo $p\n        git clone $p\n    fi\ndone &lt; $HOME\/github_links.txt<\/pre>\n<h6>0.\u6700\u7b80\u5355\/\u5e38\u7528\u7684\u901a\u914d\u7b26\u65b9\u5f0f<\/h6>\n<pre class=\"lang:default decode:true\">for i in *.txt;do\n\tmkdir ${i%.txt};\t#\u53d6txt\u6587\u4ef6\u540d\u6765\u521b\u5efa\u76ee\u5f55\n\t( cd ${i%.txt} &amp;&amp; wget -i ..\/$i --no-check-certificate );\ndone<\/pre>\n<h6>1.\u7b80\u5355\u7684\u6570\u5b57+1\u7684\u5f62\u5f0f<\/h6>\n<pre class=\"lang:default decode:true\">for((i=1; i&lt;30; i++));do\n\tdt=$(date +%Y%m%d -d \" $i days ago\")\n\techo $dt\ndone<\/pre>\n<h6>2.\u6570\u7ec4\u5f62\u5f0f<\/h6>\n<pre class=\"lang:default decode:true \">COUNTRY=('cn' 'hk' 'tw')\nfor c in ${COUNTRY[@]}\ndo\n\twget \"http:\/\/www.ipdeny.com\/ipblocks\/data\/countries\/$c.zone\"\n\tcountry_file=$c.zone\n\tIPS=$($EGREP -v \"^#|^$\" $country_file)\n\tfor ip in $IPS\n\tdo\n\t\techo \"blocking $ip\"\n\t\tiptables -A INPUT -s $ip -j DROP\n\tdone\ndone<\/pre>\n<h6>3.\u5d4c\u5957\u5faa\u73af<\/h6>\n<pre class=\"lang:default decode:true \">dirs=(papers tips tools news web pentesting database binary '%e8%bf%90%e7%bb%b4%e5%ae%89%e5%85%a8')\nfor dir in ${dirs[@]}\ndo\n\tfor i in $(seq 1 5)\n\tdo\n\tif [ \"$i\" == 1 ]\n\tthen\n\t\techo http:\/\/drops.wooyun.org\/category\/$dir\n\telse\n\t\techo http:\/\/drops.wooyun.org\/category\/$dir\/page\/$i\n\tfi\n\tdone\ndone\n\necho '###################################################'\n\ndirs=(papers tips tools news web pentesting database binary '%e8%bf%90%e7%bb%b4%e5%ae%89%e5%85%a8')\ndir_num=${#dirs[@]}\nfor((i=0;i&lt;$dir_num;i++))\ndo\n\tfor j in $(seq 1 5)\n\tdo\n\t\tif [ \"$j\" == 1 ]\n\t\tthen\n\t\t\techo http:\/\/drops.wooyun.org\/category\/${dirs[i]}\n\t\telse\n\t\t\techo http:\/\/drops.wooyun.org\/category\/${dirs[i]}\/page\/$j\n\t\tfi\n\tdone\ndone<\/pre>\n<p>\u6682\u65f6\u5c31\u5dee\u4e0d\u8fd9\u4e9b\uff0c\u4ee5\u540e\u6709\u522b\u7684tips\u518d\u53ca\u65f6\u8865\u5145\u3002<\/p>\n<div style=\"color: #000000;\">\n<h5 class=\"ts\">\u6c42\u4e00\u4e2ashell\u5faa\u73af_\u4ee5\u83b7\u53d603\u5e74\u81f3\u4eca\u7684\u6bcf\u4e00\u5929\u65e5\u671f<\/h5>\n<\/div>\n<div style=\"color: #000000;\"><span style=\"color: #000000; font-size: medium;\">\u5982\u9898\uff1a<\/span><\/div>\n<div style=\"color: #000000;\">date=`date +%Y%m%d -d &#8221; 1 days ago&#8221;`<\/div>\n<div style=\"color: #000000;\">\u628a\u91cc\u9762\u76841\u53d8\u4e3a\u4e00\u4e2a\u53d8\u91cf\uff0c\u75311-800\u5faa\u73af\uff0c\u8fd9\u6837\u5c31\u5b9e\u73b0\u4e86\u4e00\u4e2a\u671f\u95f4\u65e5\u671f\u7684\u5faa\u73af\u663e\u793a\uff0c\u5927\u6982\u5c31\u662f\u8fd9\u6837\u4e00\u4e2a\u610f\u601d\u3002<\/div>\n<div style=\"color: #000000;\"><\/div>\n<div style=\"color: #000000;\">\n<pre class=\"lang:default decode:true\">k=1\nwhile((k++&lt;=800));do\n    echo `date +%Y%m%d -d \" $k days ago\"`\ndone\n-----\nfor((i=1;i&lt;800;i++));do\n    echo $i\n    dt=$(date +%Y%m%d -d ' -'$i' day')\n    echo $dt\ndone<\/pre>\n<\/div>\n<div style=\"color: #000000;\">\u7ecf\u8fc7\u6d4b\u8bd5\u4e4b\u540eOK\uff01<\/div>\n<div style=\"color: #000000;\">\n<hr \/>\n<\/div>\n<div style=\"color: #000000;\">\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<h5>Bash\u4e2dfor\/while\u7684\u65e0\u9650\u5faa\u73af<\/h5>\n<p><strong>\u641c\u7d22\u5173\u952e\u5b57<\/strong>\uff1alinux bash while infinite loop<\/p>\n<h6>\u53c2\u8003\u89e3\u7b54\uff1a<\/h6>\n<ul>\n<li><a href=\"http:\/\/unix.stackexchange.com\/questions\/97059\/why-does-while-0-go-into-infinite-loop\" target=\"_blank\">http:\/\/unix.stackexchange.com\/questions\/97059\/why-does-while-0-go-into-infinite-loop<\/a><\/li>\n<li><a href=\"http:\/\/www.cyberciti.biz\/faq\/bash-infinite-loop\/\" target=\"_blank\">http:\/\/www.cyberciti.biz\/faq\/bash-infinite-loop\/<\/a><\/li>\n<\/ul>\n<pre class=\"lang:default decode:true \">#!\/bin\/bash\nwhile :; do\n\techo \"Press [CTRL+C] to stop..\"\n\tsleep 1\ndone\n\nwhile true; do\n\techo \"Press [CTRL+C] to stop..\"\n\tsleep 1\ndone\n\nwhile (( 1 )); do\n\techo \"Press [CTRL+C] to stop..\"\n\tsleep 1\ndone\n\nfor (( ; ; )); do\n   echo \"Pres CTRL+C to stop...\"\n   sleep 1\ndone<\/pre>\n<p>=EOF=<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u56e0\u4e3a\u5728\u7f16\u5199shell\u7684\u65f6\u5019for\u5faa\u73af\u662f\u4e2a\u6bd4\u8f83\u91cd\u8981\u7684\u8bed\u6cd5\u7ed3\u6784\uff0c\u7ecf\u5e38\u4f1a\u78b0\u5230\u6240\u4ee5\u60f3\u53ca\u65f6\u505a\u4e2a\u603b\u7ed3\/\u5907\u5fd8\uff0c\u65b9\u4fbf\u4ee5\u540e\u67e5\u9605\uff1a [&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,7,12],"tags":[83,106,107],"class_list":["post-406","post","type-post","status-publish","format-standard","hentry","category-linux","category-programing","category-tools","tag-bash","tag-for","tag-while"],"views":3797,"_links":{"self":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/406","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=406"}],"version-history":[{"count":0,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/406\/revisions"}],"wp:attachment":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/media?parent=406"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/categories?post=406"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/tags?post=406"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}