タグ

関連タグで絞り込む (1)

タグの絞り込みを解除

bashに関するlenhaiのブックマーク (2)

  • bash スクリプトの実行中上書き動作について

    を設定してから再度試した所 bar が表示された。backupcopy は編集中のファイルによって自動で判別する auto がデフォルトになっている為、試す際には明示的に yes に設定しないといけない。 bash の実装確認 evalstring.c の parse_and_execute でコマンドが処理されており、input.c の with_input_from_buffered_stream で読み込みの準備が行われている。バッファの読み込みの体は y.tab.c つまりパーサから直接呼ばれており、このパーサは fgets(3) で読み込まれつつ実行される為、一括でファイルが読み込まれている訳ではない。 while/do でループ実行した際に、ファイルを書き換えられたら戻り先はどうなるか、についてはスクリプトはバッファ付きで読み込まれており、そのバッファがファイルシステムから読

    bash スクリプトの実行中上書き動作について
    lenhai
    lenhai 2021/12/29
    ls -i でi-node確認すると分かり易い。同一i-nodeに対して読み込み(bash)と書き込みが発生してるのが問題であって、fgetsのアトミック性はあまり関係ない。なおファイル更新はmv(rename(2))でアトミックにやるのが良さそう。
  • Minimal safe Bash script template

    Published on December 14, 2020   ·   Updated on December 16, 2020 Bash scripts. Almost anyone needs to write one sooner or later. Almost no one says “yeah, I love writing them”. And that’s why almost everyone is putting low attention while writing them. I won’t try to make you a Bash expert (since I’m not a one either), but I will show you a minimal template that will make your scripts safer. You

    Minimal safe Bash script template
    lenhai
    lenhai 2021/01/18
  • 1