<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Trap on 白と黒</title><link>https://chillfixx.work/tags/trap/</link><description>Recent content in Trap on 白と黒</description><generator>Hugo</generator><language>ja</language><lastBuildDate>Thu, 05 Nov 2026 13:00:00 +0900</lastBuildDate><atom:link href="https://chillfixx.work/tags/trap/index.xml" rel="self" type="application/rss+xml"/><item><title>bashのtrapで一時ファイルを片付ける4つの落とし穴</title><link>https://chillfixx.work/blog/bash-trap-cleanup-pitfalls/</link><pubDate>Thu, 05 Nov 2026 13:00:00 +0900</pubDate><guid>https://chillfixx.work/blog/bash-trap-cleanup-pitfalls/</guid><description>&lt;h2 id="はじめに-並列に呼んだら一時ファイルの中身が混ざった"&gt;はじめに: 並列に呼んだら、一時ファイルの中身が混ざった&lt;/h2&gt;
&lt;figure&gt;
 &lt;video class="w-full rounded-2xl" src="https://chillfixx.work/blog/bash-trap-cleanup-pitfalls/overview.mp4" poster="/blog/bash-trap-cleanup-pitfalls/overview.webp" width="1200" height="675" data-motion loop muted playsinline preload="none" aria-label="一時ファイルの後片付けで踏んだ 4 つの穴と、それぞれの直し方の一覧"&gt;&lt;/video&gt;
 &lt;figcaption&gt;一時ファイルの後片付けで踏んだ 4 つの穴と、それぞれの直し方の一覧&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;本文を一時ファイルの Markdown に書き出してから処理する自作スクリプトを、2 本並列で呼んだら、片方の出力にもう片方の本文が混ざった。一時ファイルの名前を固定していたのが原因だった。&lt;/p&gt;
&lt;p&gt;実行ごとの一時ディレクトリと &lt;code&gt;trap ... EXIT&lt;/code&gt; で後片付けする形に直したが、trap の書き方で、さらに 3 つの穴を踏んだ。結論を先に書く。&lt;/p&gt;</description></item></channel></rss>