shellÓï·¨¼ì²éÏÂÁî
shell Óï·¨¼ì²éÏÂÁî°üÀ¨ shellcheck¡¢bash£¨-n Ñ¡ÏºÍ shfmt£¬ËüÃǿɼì²é shell ¾ç±¾µÄÓï·¨¹ýʧºÍÖÒÑÔ£¬ÒÔÌá¸ß׼ȷÐÔ¡¢¼°Ôç·¢Ã÷¹ýʧ¡¢×ñÊØ×î¼Ñʵ¼ù²¢¼¯³Éµ½¿ª·¢ÊÂÇéÁ÷³ÌÖС£
Shell Óï·¨¼ì²éÏÂÁî
¸ÅÊö
Shell Óï·¨¼ì²éÏÂÁîÊǼì²é Shell ¾ç±¾Óï·¨¹ýʧºÍÖÒÑԵŤ¾ß¡£ËüÃǹØÓÚÔÚÔËÐо籾֮ǰʶ±ðºÍ¸üÕý¹ýʧºÜÊÇÓÐÓá£
³£ÓõÄÏÂÁî
- shellcheck£ºÆÕ±éʹÓÃµÄ Shell ¾ç±¾Óï·¨¼ì²éÆ÷£¬Ö§³Ö Bash¡¢Zsh µÈ¡£
- bash£ºBash ×Ô¼ºµÄÓï·¨¼ì²é¹¦Ð§£¬¿ÉʹÓà -n Ñ¡ÏîÆôÓá£
- shfmt£ºÓÃÓÚÃûÌû¯ºÍ¼ì²é Shell ¾ç±¾£¬¿ÉÍ»³öÏÔʾÓï·¨¹ýʧ¡£
ÔõÑùʹÓà shellcheck
ҪʹÓà shellcheck£¬ÖÂÒâ×°Ëü£¬È»ºóÔËÐÐÒÔÏÂÏÂÁ
shellcheck
µÇ¼ºó¸´ÖÆ
ÔõÑùʹÓà bash µÄÓï·¨¼ì²é
ҪʹÓà bash µÄÓï·¨¼ì²é£¬ÇëÔËÐÐÒÔÏÂÏÂÁ
bash -n
µÇ¼ºó¸´ÖÆ
ÔõÑùʹÓà shfmt
ҪʹÓà shfmt£¬ÖÂÒâ×°Ëü£¬È»ºóÔËÐÐÒÔÏÂÏÂÁ
shfmt -l
µÇ¼ºó¸´ÖÆ
Óŵã
ʹÓÃÓï·¨¼ì²éÏÂÁî¾ßÓÐÒÔÏÂÓŵ㣺
- Ìá¸ß¾ç±¾µÄ׼ȷÐԺͿɿ¿ÐÔ¡£
- ¼°Ôç·¢Ã÷Óï·¨¹ýʧ£¬±ÜÃâÔËÐÐʱ±¬·¢¹ýʧ¡£
- ×ÊÖú×ñÊØ×î¼Ñʵ¼ùºÍ±àÂë±ê×¼¡£
×î¼Ñʵ¼ù
½¨Ò齫 Shell Óï·¨¼ì²éÏÂÁ³Éµ½¿ª·¢ÊÂÇéÁ÷³ÌÖУ¬ÀýÈ磺
- ÔÚÌá½»¾ç±¾Ö®Ç°ÔËÐмì²é¡£
- ½«¼ì²é¼¯³Éµ½Ò»Á¬¼¯³É/Ò»Á¬½»¸¶Á÷³ÌÖС£
- Ñø³É°´ÆÚ¼ì²é¾ç±¾Óï·¨µÄÏ°¹ß¡£
ÒÔÉϾÍÊÇshellÓï·¨¼ì²éÏÂÁîµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡