Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Perl で作る tiny shell
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Kei Kamikawa
June 23, 2018
Programming
3.9k
3
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Perl で作る tiny shell
Perl で極限に機能を削った shell の作り方を紹介します
Kei Kamikawa
June 23, 2018
More Decks by Kei Kamikawa
See All by Kei Kamikawa
Claude Code で Astro blog を Pages から Workers へ移行してみた
codehex
0
340
オレを救った Cline を紹介する
codehex
17
18k
どこでも使える Cloudflare Workers!
codehex
6
1.4k
htmx is fun!
codehex
3
450
すぐ使える Cloudflare Workers!
codehex
15
3.9k
Go to Cloudflare Workers
codehex
8
2.6k
AI Gateway 使っているよ!
codehex
2
2.3k
日時処理の新スタンダード: Synchro によるタイムゾーン安全、楽々開発
codehex
1
2.8k
Cloudflare Workers は楽しい!
codehex
9
3.5k
Other Decks in Programming
See All in Programming
AIに “答え“を書かせるのを やめてみた
___akari11
0
130
残高管理から台帳サービスへの進化
artoy
1
210
IBM Bob でAI駆動開発『QC-Playbook』
ichirokano2
0
120
FactoryBotをやめればRSpecは速くなるのか?
yuta_onishi_97
0
990
Unity6 URPによる海底をテーマにしたVJシステムの解説 | Unity Shader 完全に理解した 勉強会
gam0022
0
370
【加筆修正版】Laravel のアプリケーションをどこにデプロイするか #phpcon_ehime
akase244
0
160
[2026-10-09]一枚の布で作らなくてもいい。 信頼性は「パッチワーク」で紡がれる~既存の運用と新しい可能性をつなぎ合わせてきたCREの話~
tosite
0
110
Compiling a real-world CLI tool to native with Static Hermes
tmikov2023
0
130
sbt 2.0: takeoff
eed3si9n
0
170
コードで差別化できない時代の ソフトウェアエンジニアリング / Software Engineering in an Era Where Code Doesn’t Differentiate
kishida
2
190
月間100万人のサービス刷新で、 技術選定をHonoに振り切った話
yutobara
8
6.8k
Web Framework Benchmark Battle 2026, Any%
a_matsuda
2
2.7k
Featured
See All Featured
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
1.1k
The Mindset for Success: Future Career Progression
greggifford
PRO
0
540
Mobile First: as difficult as doing things right
swwweet
225
10k
Embracing the Ebb and Flow
colly
88
5.2k
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
860
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
VelocityConf: Rendering Performance Case Studies
addyosmani
331
25k
[Rails World 2026] Durable orchestration on Rails: from continuation to workflow
palkan
1
870
Prompt Engineering for Job Search
mfonobong
0
530
Mind Mapping
helmedeiros
1
400
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
400
Product Roadmaps are Hard
iamctodd
55
13k
Transcript
1FSMͰ࡞Δ UJOZTIFMM )PLLBJEPQN
!DPEFIFY !$PEF)FY w .FSDBSJ *OD w %FWFMPQJOHNJDSPTFSWJDFT w 0LJOBXBQN w
*MJLF1FSM94(P w IUUQTDPEFIFYIBUFCMPKQ
γΣϧͬͯͬͯ·͔͢
None
/P
$ pwd
$ pwd /Users/codehex
#BTI ;TI pTI
γΣϧʹ ༷ʑͳػೳ͕͋Γ·͢
ྫ͑
ύΠϓ
$ pwd | cat -n
$ pwd | cat -n 1 /Users/codehex
Ξϯυ
$ pwd && echo hello
$ pwd && echo hello /Users/codehex hello
͜ΕΒͷ ࣮Λ͍ͬͯ·͔͢ʁ
ࠓ͢༰
ࠓ͢༰ w ࠷ݶͷγΣϧͷఆٛ w ߏจղੳ w ίϚϯυͷ࣮ߦ
ࠓ͢༰ w ࠷ݶͷγΣϧͷఆٛ w ߏจղੳ w ίϚϯυͷ࣮ߦ
࠷ݶͷγΣϧͷఆٛ UJOZTIFMMͷಈ࡞Λఆٛ͢Δ
lUJOZTIFMMzNFBOT ΊͬͪΌখ͍͞γΣϧ
Ͳ͏͍͏ಈ࡞Λ͢Δ͔
Ͳ͏͍͏ಈ࡞Λ͢Δ͔ w ୯ҰίϚϯυͷ࣮ߦ $ ls w ύΠϓͷ࣮ߦ $ ls
| cat w ΞϯυʹΑΔෳ࣮ߦ $ ls && cat w αϒγΣϧόοΫάϥϯυ࣮ߦࠓճؚΊ·ͤΜ
ࠓ͢༰ w ࠷ݶͷγΣϧͷఆٛ w ߏจղੳ w ίϚϯυͷ࣮ߦ
ߏจղੳ ެจఆٛͱߏจղੳثͷ࡞
$ cat | cat -n && ls
$ cat | cat -n && ls
$ cat | cat -n && ls
$ cat | cat -n && ls
$ cat | cat -n && ls
$ cat | cat -n && ls ࠨ͔Βӈʹղऍ͠·͢
ߏจͷఆٛ
ӈʹ࿈͍݁ͯ͘͠Α͏ʹ ఆ͚ٛΛߦ͏
ߏจఆٛ • CMD: [a-zA-Z_-][0-9a-zA-Z_-]* <ARG> • ARG: [0-9a-zA-Z_-]* <ARG> |
[0-9a-zA-Z_-]* • SHLL: <PIPE> '&&' <AND> | <PIPE> • PIPE: <CMD> '|' <PIPE> | <CMD> • AND: <SHLL> '&&' <AND> | <SHLL>
ߏจղੳثͷ࡞
ߏจղੳثʹඞཁͳཁૉ
ߏจղੳثʹඞཁͳཁૉ w จࣈྻͷεΩϟφʔ w ಡΈࠐΈҐஔಡΈऔͬͨจࣈྻΛอ࣋͢Δ w จࣈྻͷϚονϯά w εΩϟφʔͰಘͨจࣈྻ͕ߏจఆٛʹϚονͨ͠ ͔Ͳ͏͔ผ͢Δ
w Ϛονͨ͠จࣈྻʹҙຯΛͨͤΔ τʔΫϯԽ w ߏจͷੜ
1FSMͰʁ
ਖ਼نදݱ
IUUQTQFSMEPDQFSMPSHQFSMPQIUNMD(@BTTFSUJPO@ l"VTFGVMJEJPNGPSAlexAMJLF TDBOOFSTJTA/\G…/gcAʜz
/\G…/gc
/\G…/gc w A/cANPEJpFSͰݱࡏϚον͍ͯ͠ΔҐஔΛ อ࣋͢Δ͜ͱ͕Ͱ͖Δɻ • pos()ͰҐஔΛऔΓग़͢͜ͱ͕Մೳ • \GͰલճAm//gAͰϚονͨ͠ҐஔΛอ࣋͢Δ͜ͱ ͕Մೳ
εΩϟφʔͱϚονϯάͷ ׂΛͭ͜ͱ͕Ͱ͖Δ ?P? W
͜͜Ͱྑ͍ใ
ΊͬͪΌࢀߟʹͳΔϖʔδ w IUUQTHJUIVCDPNLBSVQBOFSVSBQ +40/CMPCNBTUFSMJC+40/1BSTFSQN w IUUQTHJUIVCDPNLBSVQBOFSVSB50.- 1BSTFSCMPCNBTUFSMJC50.-1BSTFSQN
࣮༷ࢠ
ߏจఆٛ • CMD: [a-zA-Z_-][0-9a-zA-Z_-]* <ARG> • ARG: [0-9a-zA-Z_-]* <ARG> |
[0-9a-zA-Z_-]* • SHLL: <PIPE> '&&' <AND> | <PIPE> • PIPE: <CMD> '|' <PIPE> | <CMD> • AND: <SHLL> '&&' <AND> | <SHLL>
$.%
ߏจఆٛ • CMD: [a-zA-Z_-][0-9a-zA-Z_-]* <ARG> • ARG: [0-9a-zA-Z_-]* <ARG> |
[0-9a-zA-Z_-]* • SHLL: <PIPE> '&&' <AND> | <PIPE> • PIPE: <CMD> '|' <PIPE> | <CMD> • AND: <SHLL> '&&' <AND> | <SHLL>
4)--
ߏจఆٛ • CMD: [a-zA-Z_-][0-9a-zA-Z_-]* <ARG> • ARG: [0-9a-zA-Z_-]* <ARG> |
[0-9a-zA-Z_-]* • SHLL: <PIPE> '&&' <AND> | <PIPE> • PIPE: <CMD> '|' <PIPE> | <CMD> • AND: <SHLL> '&&' <AND> | <SHLL>
1*1&
ߏจఆٛ • CMD: [a-zA-Z_-][0-9a-zA-Z_-]* <ARG> • ARG: [0-9a-zA-Z_-]* <ARG> |
[0-9a-zA-Z_-]* • SHLL: <PIPE> '&&' <AND> | <PIPE> • PIPE: <CMD> '|' <PIPE> | <CMD> • AND: <SHLL> '&&' <AND> | <SHLL>
"/%
ΛQSJOU༷ͨ͠ࢠ $ cat | cat -n && ls
"/% 1*1& DBU DBU MT $ cat | cat -n
&& ls
ͪͳΈʹ
$ cat | cat -n && ls
$ cat | cat -n && ls ࠨ͔Βӈʹղऍ͠·͢
ͳͷͰ ΛḷΔͱ͖
"/% 1*1& DBU DBU MT $ cat | cat -n
&& ls ᶃ
"/% 1*1& DBU DBU MT $ cat | cat -n
&& ls ᶃ ᶄ ᶅ
"/% 1*1& DBU DBU MT $ cat | cat -n
&& ls ᶃ ᶄ ᶅ ᶆ ᶇ
͜ΕΛجʹ ࣮ߦ͢ΔػೳΛ࡞͠·͢
ࠓ͢༰ w ࠷ݶͷγΣϧͷఆٛ w ߏจղੳ w ίϚϯυͷ࣮ߦ
ίϚϯυͷ࣮ߦ ߏจΛجʹ࣮ߦ͢Δ
࣮ͷલʹ
ඪ४ετϦʔϜʹ͍ͭͯ
w 45%*/ 4UBOEBSE*OQVU ඪ४ೖྗ w 45%065 4UBOEBSE0VUQVU ඪ४ग़ྗ w 45%&33
4UBOEBSE&SSPS ඪ४Τϥʔग़ྗ ඪ४ετϦʔϜ
͜ΕΒ࣮࣭ ϑΝΠϧͱͯ͠ѻΘΕ·͢
୯ҰίϚϯυͷ ετϦʔϜͷϑϩʔ
$ cat
$ cat cat 45%*/
$ cat cat 45%*/ 45%065 45%&33
$ cat GPSLΛ͏ͱTIΛհ͞ͳ͍Ͱ࣮ߦՄೳ
ύΠϓͷϑϩʔ
$ fortune | cowsay
$ fortune | cowsay 45%*/ PS/PU ᶃ
$ fortune | cowsay 45%*/ PS/PU 45%065 ᶃ ᶄ
$ fortune | cowsay 45%*/ PS/PU 45%065 45%*/ ᶃ ᶄ
ᶅ
$ fortune | cowsay 45%*/ PS/PU 45%065 45%*/ 45%065 ᶃ
ᶄ ᶅ ᶆ
͜ΕΒͷίϚϯυ ผϓϩηεͰಈ͍͍ͯ·͢
$ ps a | cat 1*%
ύΠϓͷ࣮
pipe my ($r, $w);
w $r͕3FBEFS $w͕8SJUFS w 8SJUFSʹσʔλ͕ॻ͖ࠐ·Εͨͱ͖ 3FBEFSͰͦͷσʔλΛಡΈऔΔ͜ͱ͕Մೳ pipe my ($r, $w);
֤ϓϩηεؒͷετϦʔϜΛ pipe()Ͱܨ͛Δ͜ͱͰ࣮Մೳ
ͦͷ࣌ͷϑϩʔ
$ fortune | cowsay 45%*/ PS/PU 45%065 ᶃ ᶄ
$ fortune | cowsay 45%*/ PS/PU 45%065 ᶃ ᶄ ᶅ
ᶆ 8SJUFS 3FBEFS
$ fortune | cowsay 45%*/ PS/PU 45%065 45%*/ 45%065 ᶃ
ᶄ ᶅ ᶆ 8SJUFS 3FBEFS ᶇ ᶈ ᶉ
ͳͷͰ࣮࣭ ͜ͷΑ͏ʹߟ͑ΒΕΔ
$ fortune | cowsay 45%*/ PS/PU 8SJUFS 3FBEFS 45%065 ᶃ
ᶄ ᶅ ᶆ
None
w ίϚϯυOPEFͰ͔ͭOPEF͕ύΠϓͰͳ͍ ߹ଈίϚϯυΛ࣮ߦ w ͦΕҎ֎ίϚϯυΛอ࣋͢Δ w ύΠϓOPEF͔͕ͭύΠϓOPEFͰͳ͍߹ อ࣋͠ଓ͚ͨίϚϯυΛ࣮ߦ
Ξϯυͷϑϩʔ
$ echo hello && echo world
$ echo hello && echo world ᶃ
$ echo hello && echo world ᶃ ᶄ
w ΞϯυOPEFʹདྷΔ·ͰʹࠨͷOPEFΛ શ࣮ͯߦ͢Δ w ޭͨ͠߹ӈͷOPEFΛࠨͷOPEFͱಉ͡Α͏ ʹ࣮ߦ͢Δ
͜Ε͚ͩͰ UJOZTIFMM͕͠·͢ʂ
·ͱΊ
·ͱΊ w ӈʹ࿈͍݁ͯ͘͠Α͏ʹߏจఆٛͨ͠ w γΣϧͷύΠϓɺΞϯυػೳΛཧղͯ͠ɺղੳ࣌ʹ ࣮ߦ͢ΔػೳΛ࡞ͨ͠
࣭Ͳ͏ͧ https://github.com/Code-Hex/p5-Shell-Tiny