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
Use Perl as Better Shell Script
Search
karupanerura
May 31, 2025
Programming
0
720
Use Perl as Better Shell Script
Houtou.pm #1
karupanerura
May 31, 2025
Tweet
Share
More Decks by karupanerura
See All by karupanerura
GoでParserを書く
karupanerura
4
920
マイ隙間家具OSSたちのご紹介
karupanerura
2
260
Mustache Template 話 2024
karupanerura
0
27
1つの言語を原点に色々な言語を学ぶということ
karupanerura
4
2.9k
Javaの実装をPerlでテストする
karupanerura
0
1.2k
Go Generics Overview
karupanerura
0
1.3k
Japan.pm 2021 開催まで至る道
karupanerura
0
2.1k
Perl MongersのためのAWS_CDK入門
karupanerura
0
140
Webシステムのパフォーマンス・チューニング
karupanerura
2
840
Other Decks in Programming
See All in Programming
PipeCDのプラグイン化で目指すところ
warashi
1
310
What's new in AppKit on macOS 26
1024jp
0
150
AI駆動のマルチエージェントによる業務フロー自動化の設計と実践
h_okkah
0
230
React は次の10年を生き残れるか:3つのトレンドから考える
oukayuka
21
6.7k
Advanced Micro Frontends: Multi Version/ Framework Scenarios @WAD 2025, Berlin
manfredsteyer
PRO
0
400
Claude Code派?Gemini CLI派? みんなで比較LT会!_20250716
junholee
1
540
The Niche of CDK Grant オブジェクトって何者?/the-niche-of-cdk-what-isgrant-object
hassaku63
1
620
Agentic Coding: The Future of Software Development with Agents
mitsuhiko
0
130
The Evolution of Enterprise Java with Jakarta EE 11 and Beyond
ivargrimstad
0
270
GPUを計算資源として使おう!
primenumber
1
250
「App Intent」よくわからんけどすごい!
rinngo0302
1
110
Goで作る、開発・CI環境
sin392
0
260
Featured
See All Featured
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
34
5.9k
A better future with KSS
kneath
238
17k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
29
1.8k
What’s in a name? Adding method to the madness
productmarketing
PRO
23
3.5k
Rails Girls Zürich Keynote
gr2m
95
14k
Product Roadmaps are Hard
iamctodd
PRO
54
11k
For a Future-Friendly Web
brad_frost
179
9.8k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
Embracing the Ebb and Flow
colly
86
4.8k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
667
120k
How GitHub (no longer) Works
holman
314
140k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
126
53k
Transcript
Use Perl as Better Shell Script @karupanerura Houtou.pm #1
@karupanerura • Perl / Go / Java / TypeScript /etc..
• PAUSE: KARUPA • Software Engineer @ DeNA, Co,. LTD. • Chief Director @ Japan Perl Association
ࢁསͱࢲ • όϯυ • Live @ KAZOO HALL • ٢ా͏ͲΜ
• ͖ • ࢁསେֶϫΠϯ • ͏·͍ https://www.yamanashi.ac.jp/social/3131
None
Shell Script
Shell Script • ShellߏจΛͦͷ··ར༻ͨ͠εΫϦϓτ • ίϚϯυΛॻ͍ͯͦͷ··࣮ߦͰ͖ΔͷͰײత • CLIϕʔεͷૢ࡞ΛࣗಈԽ͢Δͷʹศར • WebܥͷਓͳΒ1ॻ͍ͨ͜ͱ͋Δͣʁ
None
؆୯ʂศརʂ
؆୯……ʁ
Shell Scriptͷ͠͞ • ίϚϯυͷڥࠩҟ • macOSͱLinuxͰsedawkͳͲͰBSD/GNUҧ͍͕͋ΔʢΦϓγϣϯ͕ҟͳΔʣ • ref. https://speakerdeck.com/mackee/perl-for-shell-awk-and-sed-programmers •
࣮ࡍͷίϚϯυͱϏϧτΠϯίϚϯυͱγΣϧߏจ͕ࠞࡏ͢Δ • bashͷtestͱ[ͱ[[ͷҧ͍Λઆ໌Ͱ͖ΔͬͯਓͲΕ͘Β͍͍·͔͢ʁ • ෳࡶͳσʔλߏΛѻ͏ͷ͕ۤख
খωλ: testͱ[ͱ[[ͷҧ͍ bash-5.2$ type [ [ γΣϧΈࠐΈؔͰ͢ bash-5.2$ type test
test γΣϧΈࠐΈؔͰ͢ bash-5.2$ type [[ [[ γΣϧͷ༧ޠͰ͢
খωλ: testͱ[ͱ[[ͷҧ͍ bash-5.2$ type [ [ γΣϧΈࠐΈؔͰ͢ bash-5.2$ type test
test γΣϧΈࠐΈؔͰ͢ bash-5.2$ type [[ [[ γΣϧͷ༧ޠͰ͢ ಉ͡ΈࠐΈؔ(alias) ߏจʢਖ਼نදݱͳͲαϙʔτʣ
ෳࡶͳσʔλߏͬͯͨͱ͑ • HashMap(Dict)ͷதʹ͞ΒʹHashMap(Dict)Λ࣋ͭͱ͔ • {"user1":{"user2":true}} • ͦͷͳ͔ʹ͞ΒʹArrayΛ࣋ͭͱ͔ • {"user1":{"user2":[100,200]}}
ෳࡶͳσʔλߏ in Shell Script $ declare -A data=(["user1"]=(["user2"]=true)) bash: ༧ظ͠ͳ͍τʔΫϯ
`(' पลʹߏจΤϥʔ͕͋Γ·͢
ෳࡶͳσʔλߏ in Shell Script $ declare -A data=(["user1"]=(["user2"]=true)) bash: ༧ظ͠ͳ͍τʔΫϯ
`(' पลʹߏจΤϥʔ͕͋Γ·͢ ʢૉʹʣ Ͱ͖ͳ͍
ෳࡶͳ͜ͱΛ͢Δͷ͍͠
͍͜͠ͱΛ͍ͨ͠ͱ͖……?
ಠஅͱภݟʹΑΓϓϩάϥϛϯάݴޠΛൺֱ • Ruby/Go/JavaScript/PHP: ڥʹΑͬͯೖ͍ͬͯͳ͍ • Python • ͍·Ͱ͍͍ͩͨͷڥʹPython3ܥ͕ೖ͍ͬͯΔ • Shellͱߏจ͕͍ͩͿҧ͏ͷͰॻ͖͕͑ͪΐͬͱखؒ
• Perl • ͍͍ͩͨͷڥʹೖ͍ͬͯΔ͠Shellͱߏจ͍ۙ
PerlͱbashͷߏจΛൺֱ #!/usr/bin/perl use strict; use warnings; # コマンドライン引数の取得 my $arg1
= shift @ARGV; # 配列の宣言 my @array; # コマンドの実行 system 'grep status:500 /var/log/ access.log | ...'; #!/bin/bash set -ue -o pipefail # コマンドライン引数の取得 arg1=$1; shift # 配列の宣言 declare -a array # コマンドの実行 grep status:500 /var/log/access.log | ...
PerlͱbashͷߏจΛൺֱ # ίϚϯυΛ࣮ߦͯ݁͠ՌΛมʹೖΕ͍ͨ my $result = `grep status:500 file`; #
݅ذ if ($x > 0) { ... } # ϧʔϓ while ($x > 0) { ... } # ίϚϯυΛ࣮ߦͯ݁͠ՌΛมʹೖΕ͍ͨ result=`grep status:500 file` # ݅ذ if [[ "$x" -gt 0 ]]; then ... fi # ϧʔϓ while [[ "$x" -gt 0 ]]; do ... done
Perl͡ΌΜ (?)
࣮ྫհͷίʔφʔ
ྫ: json-diff https://github.com/karupanerura/dot fi les/blob/master/bin/json-diff
ྫ: jwt https://github.com/karupanerura/dot fi les/blob/master/bin/jwt
༨ஊ: zxͱ͍͏ͭ͋Δ https://github.com/google/zx ׳ΕͯखʹೃછΊΑ͍͔
·ͱΊ
·ͱΊ • Shell Scriptศར͚ͩͲෳࡶͳ͜ͱΛΖ͏ͱ͢Δͱ͍͠ • ෳࡶͳ͜ͱΛΓ͍ͨͱ͖ϓϩάϥϛϯάݴޠʹஔ͖͑ΔͱΑ͍ • PerlShell Scriptͱߏจ͕͍ۙͷͰҠ২ϋʔυϧ͕͍ʢͱࢥ͏ʣ •
ਖ਼ղ͕͋ΔΘ͚Ͱͳ͍ͷͰɺΓ͍͢ํ๏Λࡧ͠·͠ΐ͏