ʹÓà Bash ÖÆ×÷ Web Çå¾²ÑÕÉ«
µ±ÅÌËã»úÏÔʾÆ÷µÄµ÷É«°åÓÐÏÞʱ£¬ÍøÒ³Éè¼Æʦͨ³£Ê¹ÓÃÒ»×é web Çå¾²ÑÕÉ« À´½¨ÉèÍøÕ¾¡£ËäÈ»ÔÚ½ÏÐÂ×°±¸ÉÏÏÔʾµÄÏÖ´úÍøÕ¾¿ÉÒÔÏÔʾ±È×î³õµÄ web Çå¾²µ÷É«°å¸ü¶àµÄÑÕÉ«£¬µ«ÎÒÓÐʱϲî³ØÚ½¨ÉèÍøҳʱ²Î¿¼ web Çå¾²ÑÕÉ«¡£ÕâÑùÎÒ¾ÍÖªµÀÎÒµÄÍøÒ³ÔÚÈκεط½¶¼¿´ÆðÀ´²»´í¡£
Äã¿ÉÒÔÔÚÍøÉÏÕÒµ½ Web Çå¾²µ÷É«°å£¬µ«ÎÒÏëÓµÓÐ×Ô¼ºµÄ¸±±¾ÒÔÀû±ã²Î¿¼¡£ÄãÒ²¿ÉÒÔʹÓà Bash ÖÐµÄ for Ñ»·½¨ÉèÒ»¸ö¡£
Bash for Ñ»·
Bash ÖÐµÄ for Ñ»· µÄÓï·¨ÈçÏÂËùʾ£º
for ±äÁ¿ in ÜöÝÍ ; do Óï¾ä ; done
µÇ¼ºó¸´ÖÆ
ÀýÈ磬¼ÙÉèÄãÏë´òÓ¡´Ó 1 µ½ 3 µÄËùÓÐÊý×Ö¡£Äã¿ÉÒÔ¿ìËÙÔÚ Bash ÏÂÁîÐÐÉϱàдһ¸ö for Ñ»·À´ÎªÄãÍê³ÉÕâÏîÊÂÇ飺
$ for n in 1 2 3 ; do echo $n ; done123
µÇ¼ºó¸´ÖÆ
·ÖºÅÊDZê×¼µÄ Bash Óï¾äÍÑÀë·û¡£ËüÃÇÔÊÐíÄãÔÚÒ»ÐÐÖбàд¶à¸öÏÂÁî¡£ÈôÊÇÄãÒªÔÚ Bash ¾ç±¾ÎļþÖаüÀ¨Õâ¸ö for Ñ»·£¬Äã¿ÉÒÔÓû»ÐзûÌæ»»·ÖºÅ²¢ÏñÕâÑùд³ö for Ñ»·£º
for n in 1 2 3doecho $ndone
µÇ¼ºó¸´ÖÆ
ÎÒϲ»¶½« do ºÍ for ·ÅÔÚͳһÐУ¬ÕâÑùÎÒ¸üÈÝÒ×ÔĶÁ£º
for n in 1 2 3 ; doecho $ndone
µÇ¼ºó¸´ÖÆ
Ò»´Î¶à¸ö for Ñ»·
Äã¿ÉÒÔ½«Ò»¸öÑ»··ÅÔÚÁíÒ»¸öÑ»·ÖС£Õâ¿ÉÒÔ×ÊÖúÄãµü´ú¶à¸ö±äÁ¿£¬Ò»´Î×ö²»Ö¹Ò»¼þÊ¡£¼ÙÉèÄãÏë´òÓ¡³ö×Öĸ A¡¢B ºÍ C ÓëÊý×Ö 1¡¢2 ºÍ 3 µÄËùÓÐ×éºÏ¡£Äã¿ÉÒÔÔÚ Bash ÖÐʹÓÃÁ½¸ö for Ñ»·À´ÊµÏÖ£¬ÈçÏÂËùʾ£º
#!/bin/bashfor number in 1 2 3 ; dofor letter in A B C ; doecho $letter$numberdonedone
µÇ¼ºó¸´ÖÆ
ÈôÊǽ«ÕâЩÐзÅÔÚÃûΪ for.bash µÄ Bash ¾ç±¾ÎļþÖв¢ÔËÐÐËü£¬Äã»á¿´µ½¾ÅÐÐÏÔʾÁËËùÓÐ×ÖĸÓëÿ¸öÊý×ÖÅä¶ÔµÄ×éºÏ£º
$ bash for.bashA1B1C1A2B2C2A3B3C3
µÇ¼ºó¸´ÖÆ
±éÀú Web Çå¾²ÑÕÉ«
Web Çå¾²ÑÕÉ«ÊÇ´ÓÊ®Áù½øÖÆÑÕÉ« #000£¨ÐþÉ«£¬¼´ºìÉ«¡¢ÂÌÉ«ºÍÀ¶É«Öµ¾ùΪÁ㣩µ½ #fff£¨°×É«£¬¼´ºìÉ«¡¢ÂÌÉ«ºÍÀ¶É«¾ùΪ×î¸ß£©£¬Ã¿¸öÊ®Áù½øÖÆÖµµÄ²½½øΪ 0¡¢3¡¢6¡¢9¡¢c ºÍ f¡£
Äã¿ÉÒÔÔÚ Bash ÖÐʹÓÃÈý¸ö for Ñ»·ÌìÉú Web Çå¾²ÑÕÉ«µÄËùÓÐ×éºÏµÄÁÐ±í£¬ÆäÖÐÑ»·±éÀúºìÉ«¡¢ÂÌÉ«ºÍÀ¶É«Öµ¡£
#!/bin/bashfor r in 0 3 6 9 c f ; dofor g in 0 3 6 9 c f ; dofor b in 0 3 6 9 c f ; doecho "#$r$g$b"donedonedone
µÇ¼ºó¸´ÖÆ
ÈôÊǽ«ÆäÉúÑÄÔÚÃûΪ websafe.bash µÄРBash ¾ç±¾Öв¢ÔËÐÐËü£¬Äã¾Í»á¿´µ½ËùÓÐ Web Çå¾²ÑÕÉ«µÄÊ®Áù½øÖÆÖµµÄµü´ú£º
$ bash websafe.bash | head#000#003#006#009#00c#00f#030#033#036#039
µÇ¼ºó¸´ÖÆ
ÒªÖÆ×÷¿ÉÓÃ×÷ Web Çå¾²ÑÕÉ«²Î¿¼µÄ HTML Ò³Ã棬ÄãÐèҪʹÿ¸öÌõÄ¿³ÉΪһ¸öµ¥¶ÀµÄ HTML ÔªËØ¡£½«Ã¿ÖÖÑÕÉ«·ÅÔÚÒ»¸ö
ÔªËØÖУ¬²¢½«Åä¾°ÉèÖÃΪ Web Çå¾²ÑÕÉ«¡£ÎªÁËʹʮÁù½øÖÆÖµ¸üÒ×ÓÚÔĶÁ£¬½«Æä·ÅÔÚµ¥¶ÀµÄ
ÔªËØÖС£½« Bash ¾ç±¾¸üÐÂΪÈçÏ£º<div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false">#!/bin/bashfor r in 0 3 6 9 c f ; dofor g in 0 3 6 9 c f ; dofor b in 0 3 6 9 c f ; doecho "<div style="background-color:#$r$g$b"><code>#$r$g$b</code></div>"donedonedone</pre><div class="contentsignin">µÇ¼ºó¸´ÖÆ</div></div> <p>µ±ÄãÔËÐÐÐ嵀 Bash ¾ç±¾²¢½«Ð§¹ûÉúÑĵ½ HTML Îļþʱ£¬Äã¿ÉÒÔÔÚä¯ÀÀÆ÷ÖÐÉó²éËùÓÐ Web Çå¾²ÑÕÉ«µÄÊä³ö£º</p> <div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false">$ bash websafe.bash &gt; websafe.html</pre><div class="contentsignin">µÇ¼ºó¸´ÖÆ</div></div> <p style="text-align:center;"><img src="https://img.php.cn/upload/article/000/887/227/168872725169624.jpg" alt="ʹÓà Bash ÖÆ×÷ Web Çå¾²ÑÕÉ«"></p> <p><em>Colour gradient.</em></p> <p>Õâ¸öÍøÒ³²»ÊǺÜÔÃÄ¿¡£ÉîÉ«Åä¾°ÉϵÄÐþÉ«ÎÄ×ÖÎÞ·¨ÔĶÁ¡£ÎÒϲ»¶Ê¹ÓÃHTMLÑùʽ£¬ÒÔÈ·±£ÔÚÑÕÉ«¾ØÐÎÉÏÒÔ°×É«Îı¾ÏÔʾʮÁù½øÖÆÖµ£¬²¢ÇÒÅ侰ΪÐþÉ«¡£ÎÒʹÓÃÁËHTMLÍø¸ñÑùʽ½«Ã¿ÐÐÁù¸ö¿ò¾ÙÐÐÅÅÁУ¬²¢ÎªÁËÑŹÛЧ¹û£¬ÔÚ¿òÖ®¼äÁôÓÐÊʵ±µÄ¼ä¾à¡£</p> <p>ÄãÐèÒªÔÚÑ»·Ö®Ç°ºÍÖ®ºó°üÀ¨ÆäËûµÄHTMLÔªÏòÀ´Ìí¼ÓÌØÁíÍâÑùʽ¡£ÔÚ¶¥²¿µÄHTML´úÂëÖнç˵Ñùʽ£¬²¢Ôڵײ¿µÄHTML´úÂëÖйرÕËùÓÐÒÑ·¿ªµÄHTML±êÇ©</p> <div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false">#!/bin/bashcat<title>Web-safe colors</title><meta name="viewport" content="width=device-width, initial-scale=1"><style>div {padding-bottom: 1em;}code {background-color: black;color: white;}@media only screen and (min-width:600px) {body {display: grid;grid-template-columns: repeat(6,1fr);column-gap: 1em;row-gap: 1em;}div {padding-bottom: 3em;}}</style>EOFfor r in 0 3 6 9 c f ; dofor g in 0 3 6 9 c f ; dofor b in 0 3 6 9 c f ; doecho "<divstyle><code>#$r$g$b</code></divstyle></pre><div class="contentsignin">µÇ¼ºó¸´ÖÆ</div></div>
“donedonedonecat
ÒÔÉϾÍÊÇʹÓà Bash ÖÆ×÷ Web Çå¾²ÑÕÉ«µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡