Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
bashの組み込みコマンド
Search
Satoru Takeuchi
PRO
June 24, 2022
Technology
1
200
bashの組み込みコマンド
以下動画のテキストです
https://youtu.be/6oVvcnwRUa0
Satoru Takeuchi
PRO
June 24, 2022
Tweet
Share
More Decks by Satoru Takeuchi
See All by Satoru Takeuchi
「Linux」という言葉が指すもの
sat
PRO
3
95
APIとABIの違い
sat
PRO
5
62
ファイルシステムへのアクセス方法
sat
PRO
0
26
ファイルシステム
sat
PRO
1
34
低レイヤソフトウェア技術者が YouTuberとして食っていこうとした話
sat
PRO
7
6.1k
ポーリングと割り込み
sat
PRO
1
80
Rook: Intro and Deep Dive With Ceph
sat
PRO
1
140
会社員しながら本を書いてきた知見の共有
sat
PRO
3
880
デバイスにアクセスするデバイスファイル
sat
PRO
1
62
Other Decks in Technology
See All in Technology
ガチな登山用デバイスからこんにちは
halka
1
240
Webブラウザ向け動画配信プレイヤーの 大規模リプレイスから得た知見と学び
yud0uhu
0
230
AWSを利用する上で知っておきたい名前解決のはなし(10分版)
nagisa53
10
3k
「どこから読む?」コードとカルチャーに最速で馴染むための実践ガイド
zozotech
PRO
0
290
La gouvernance territoriale des données grâce à la plateforme Terreze
bluehats
0
150
「何となくテストする」を卒業するためにプロダクトが動く仕組みを理解しよう
kawabeaver
0
380
[ JAWS-UG 東京 CommunityBuilders Night #2 ]SlackとAmazon Q Developerで 運用効率化を模索する
sh_fk2
3
380
バイブスに「型」を!Kent Beckに学ぶ、AI時代のテスト駆動開発
amixedcolor
2
530
20250913_JAWS_sysad_kobe
takuyay0ne
2
110
エラーとアクセシビリティ
schktjm
1
1.2k
企業の生成AIガバナンスにおけるエージェントとセキュリティ
lycorptech_jp
PRO
2
160
2025年になってもまだMySQLが好き
yoku0825
8
4.7k
Featured
See All Featured
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
34
3.1k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3k
How to train your dragon (web standard)
notwaldorf
96
6.2k
The World Runs on Bad Software
bkeepers
PRO
70
11k
Gamification - CAS2011
davidbonilla
81
5.4k
A Modern Web Designer's Workflow
chriscoyier
696
190k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
285
13k
A Tale of Four Properties
chriscoyier
160
23k
Automating Front-end Workflow
addyosmani
1370
200k
Build your cross-platform service in a week with App Engine
jlugia
231
18k
What’s in a name? Adding method to the madness
productmarketing
PRO
23
3.7k
Bootstrapping a Software Product
garrettdimon
PRO
307
110k
Transcript
bashの組み込みコマンド Jun. 24th, 2022 Satoru Takeuchi twitter: satoru_takeuchi
bashの組み込みコマンドとは • bash上で”help”を実行すると出てくるコマンドたち • 新規プロセスを生成せずにbash自身が処理 • 種類 ◦ “if”や”for”などの制御構文 ◦
echoなどの頻出コマンド ◦ waitやcdなどの組み込みコマンドでなければ実現できないもの
echoはなぜ組み込みコマンドなのか • bashスクリプト内で頻出するので高速なほうが都合がよい ◦ /bin/echoを実行するとbashを親とした新規プロセスの生成が必要 ◦ 組み込みコマンドなら新規プロセスの生成が不要 • 実験: 組み込みコマンド(echo)
vs 実行ファイル(/bin/echo) ◦ bashスクリプト内で10000回実行したときの所要時間を比較 • 📝 実はtimeも組み込みコマンド ◦ しかも組み込みコマンドと実行ファイルで微妙にデフォルト出力が違う
waitはなぜ組み込みコマンドなのか • “wait”は子プロセスの終了を親が待つシステムコール ◦ 子ではないプロセスの終了は待てない • “man 2 wait”より抜粋 ◦
All of these system calls are used to wait for state changes in a child of the calling process, and obtain information about the child whose state has changed.
cdはなぜ組み込みコマンドなのか • “cd”は内部的に”chdir”システムコールを呼ぶ • “chdir”はシステムコールを呼んだプロセスのワーキングディレクトリを変更 • “man 2 chdir”より抜粋 ◦
chdir() changes the current working directory of the calling process to the directory specified in path. • 親プロセス(bash)には影響を及ぼさない
まとめ • bashには組み込みコマンドが存在する • 組み込みコマンドにする目的はさまざま ◦ 高速化 ◦ そもそも実行ファイルでは実現できない