Submit Search
Upload
ShellCheckを使おう
•
0 likes
•
97 views
Hideaki Miyake
Follow
「新しいLinuxの教科書」を読む会 オンライン #13 の発表資料です。 https://linuxbook.connpass.com/event/211627/
Read less
Read more
Software
Report
Share
Report
Share
1 of 57
Download now
Download to read offline
Recommended
2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
Marius Sescu
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Expeed Software
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
Skeleton Culture Code
Skeleton Culture Code
Skeleton Technologies
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
Recommended
2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
Marius Sescu
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Expeed Software
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
Skeleton Culture Code
Skeleton Culture Code
Skeleton Technologies
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
Introduction to Data Science
Introduction to Data Science
Christy Abraham Joy
Time Management & Productivity - Best Practices
Time Management & Productivity - Best Practices
Vit Horky
The six step guide to practical project management
The six step guide to practical project management
MindGenius
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
RachelPearson36
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Applitools
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
GetSmarter
ChatGPT webinar slides
ChatGPT webinar slides
Alireza Esmikhani
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
Project for Public Spaces & National Center for Biking and Walking
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
DevGAMM Conference
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
Erica Santiago
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Saba Software
Introduction to C Programming Language
Introduction to C Programming Language
Simplilearn
More Related Content
Featured
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
Introduction to Data Science
Introduction to Data Science
Christy Abraham Joy
Time Management & Productivity - Best Practices
Time Management & Productivity - Best Practices
Vit Horky
The six step guide to practical project management
The six step guide to practical project management
MindGenius
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
RachelPearson36
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Applitools
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
GetSmarter
ChatGPT webinar slides
ChatGPT webinar slides
Alireza Esmikhani
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
Project for Public Spaces & National Center for Biking and Walking
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
DevGAMM Conference
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
Erica Santiago
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Saba Software
Introduction to C Programming Language
Introduction to C Programming Language
Simplilearn
Featured
(20)
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Getting into the tech field. what next
Getting into the tech field. what next
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
How to have difficult conversations
How to have difficult conversations
Introduction to Data Science
Introduction to Data Science
Time Management & Productivity - Best Practices
Time Management & Productivity - Best Practices
The six step guide to practical project management
The six step guide to practical project management
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
ChatGPT webinar slides
ChatGPT webinar slides
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Introduction to C Programming Language
Introduction to C Programming Language
ShellCheckを使おう
1.
ShellCheckを使おう 2021年05月22日
2.
自己紹介 名前: 三宅 英明 Twitter:
@mollifier 神戸のプログラマ
3.
ShellCheckを使おう 目次 ShellCheckとは ShellCheckをインストールする ShellCheckの使い方 ShellCheckのissueを無視する
4.
ShellCheckとは
5.
ShellCheckとは bashの文法や構文は、わりと「ゆるふわ」なところが あります
6.
ShellCheckとは たとえば、未定義の変数をいきなり参照してもエラー にならない
7.
ShellCheckとは message=hello echo $msg #=>
空行が出力される
8.
ShellCheckとは それに、細かな記号の使い方によって動作が変わる ところもあります
9.
ShellCheckとは message="hello world" echo $message
#=> hello worldと出力される(ス ペースが1つだけになる)
10.
ShellCheckとは message="hello world" echo "$message"
#=> hello worldと出力さ れる
11.
ShellCheckとは echo $message でも
echo "$message" でも、どち らも文法上は誤りではない。 ただし、""の有無によって動作が変わる。
12.
ShellCheckとは message="helloworld" echo $message echo "$message" $messageに入っている文字列にスペースやタブが 含まれていないなら、""をつけてもつけなくても結果は 同じ
13.
ShellCheckとは message="hello world" echo "$message" スペースやタブが入っていて、それをそのまま出力し たいなら""で囲まなければならない
14.
ShellCheckとは でも、""で囲まなくても文法の間違いではない
15.
ShellCheckとは なので実行してもエラーにはならない。bashは間違 いを教えてくれない こういうのはソースコードを見て見つけるか、テストを して直すしかない
16.
ShellCheckとは それも大変。 こういう間違いを見つけてくれるやつはないのか?
17.
ShellCheckとは そういうときにShellCheckが役に立ちます
18.
ShellCheckとは https://www.shellcheck.net/
19.
ShellCheckとは ShellCheckとは、bashやshのソースコードを解析し て、推奨されなかったり不具合を起こしやすかったり する書き方を探して指摘してくれるツール
20.
ShellCheckをインストールする
21.
ShellCheckをインストールする Ubuntuではパッケージが用意されているので、すぐイ ンストールできます $ sudo apt
install shellcheck
22.
ShellCheckをインストールする CentOSの場合、EPELの中にパッケージがあります $ dnf install
epel-release $ dnf install ShellCheck EPEL = Extra Packages for Enterprise Linux
23.
ShellCheckをインストールする Macの場合、Homebrewのパッケージがあります $ brew install
shellcheck
24.
ShellCheckをインストールする その他の環境でも、公式のインストール方法の説明を 読めばできるでしょう https://github.com/koalaman/shellcheck#user -content-installing
25.
ShellCheckの使い方
26.
ShellCheckの使い方 ShellCheckの基本的な使い方
27.
ShellCheckの使い方 shellcheck チェックしたいファイル、というふうに使う
28.
ShellCheckの使い方 実行している例 $ shellcheck test/check1.sh
29.
ShellCheckの使い方 出力の例 In test/check1.sh line
4: echo $message ^------^ SC2086: Double quote to prevent globbing and word splitting. Did you mean: echo "$message"
30.
ShellCheckの使い方 出力の例の続き For more information: https://www.shellcheck.net/wiki/SC2086 --
Double quote to prevent globbing ...
31.
ShellCheckの使い方 ShellCheckでは見つけた問題のことをissueと呼び ます
32.
ShellCheckの使い方 さきほどの例では、一つのissueが見つかりました
33.
ShellCheckの使い方 In test/check1.sh line
4: issueが見つかったファイル名と行番号
34.
ShellCheckの使い方 echo $message ^------^ SC2086:
Double quote to prevent globbing and word splitting. issueにはそれぞれ一意的な識別子が割り当てられ ています。 それをshellcheckではcodeと呼んでいま す。 今回見つかったissueのcodeはSC2086です。
35.
ShellCheckの使い方 ^------^ SC2086: Double
quote to prevent globbing and word splitting. その後ろにはissueのタイトルが出力されています。こ こを見ればなにが問題なのかの概要が分かります。
36.
ShellCheckの使い方 Did you mean: echo
"$message" その下には直し方の見本が出力されます
37.
ShellCheckの使い方 For more information: https://www.shellcheck.net/wiki/SC2086 --
Double quote to prevent globbing ... 最後に、このissueの詳細が書かれているドキュメント へのリンクURLが紹介されています。
38.
ShellCheckの使い方 ShellCheckのドキュメントは優秀で、すべてのissue に詳しい説明が書かれています。
39.
ShellCheckの使い方 これを読めば、なぜだめなのか、どういう場合に問題 が発生するのかが分かります
40.
ShellCheckの使い方 中にはExceptions(例外)という項目が書かれた issueもあります。 こういう場合はしょうがないのでこのissueを無視して もよいかもね、という説明です
41.
ShellCheckの使い方 ShellCheckのドキュメントを読むだけでも勉強になり ます。参考にしてください
42.
ShellCheckのissueを無視する ShellCheckの指摘はかなり厳しいです 実際には、厳しすぎてどうしても一部無視しないとい けないこともあります
43.
ShellCheckのissueを無視する そういうときは、ソースコードに次の形式でコメントを 書きます # shellcheck disable=issueのcode
44.
ShellCheckのissueを無視する これで、その次の行は指定したcodeのissueは無視さ れて、出力されません
45.
ShellCheckのissueを無視する 例 message="hello world" # shellcheck
disable=SC2086 echo $message
46.
ShellCheckのissueを無視する または、ShellCheckの起動オプションで -e または
- -exclude を指定しても無視できます
47.
ShellCheckのissueを無視する -e issueのcode または --exclude=issueのcode で指定します
48.
ShellCheckのissueを無視する 複数のissueを無視したい場合は , 区切りで並べて 指定します
49.
ShellCheckのissueを無視する 例 $ shellcheck -e
SC2086,SC2087 check1.sh
50.
ShellCheckのissueを無視する ただし、あんまり無視しすぎるとShellCheck使ってる 意味がなくなるので、ほどほどに
51.
ShellCheckのissueを無視する 状況に応じて使ってください
52.
まとめ
53.
まとめ ShellCheckを使うと、シェルの罠や間違いやすいポイ ントを回避できます
54.
まとめ 先人たちの英知がつまっているので、きっと知らなか ったissueがあるはずです
55.
まとめ ShellCheckを使ってシェルスクリプトの品質を高めま しょう
56.
まとめ ありがとうございました
57.
ShellCheckを使おう 目次 ShellCheckとは ShellCheckをインストールする ShellCheckの使い方 ShellCheckのissueを無視する
Download now