タグ

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

タグの絞り込みを解除

shellscriptとtroubleshootに関するdynamicsoarのブックマーク (2)

  • bashで変数を正規表現で置換して変数に代入する方法

    bashで変数を置換して変数に代入する方法を紹介します。 ネットで上記の方法を調べたのですが、bashの変数を正規表現の入力にしたりとか、置換結果を変数に代入する記事があまりみつからなかったので、このエントリーでまとめておきます。 ビギナーの方向けの内容です。文字列置換ではsedを前提とします。 1.問題点 例えば、 00012345 というテキストを含むファイル「foo.txt」から「12345」を抜き出したい場合、コマンドラインで次のように実行します。 #!/bin/sh sed -e "s/[0]*\(12345\)/\1/" foo.txt 上記の内容を「foo.sh」というファイルに保存して実行すると、標準出力に「12345」を出力します。 % ./foo.sh 12345 ですが、以下のことが分かりません。 テキストファイルではなく、bashの変数を入力にしたい 置換後の内容を

    bashで変数を正規表現で置換して変数に代入する方法
    dynamicsoar
    dynamicsoar 2019/09/01
    全く同じところで詰まっていたので助かった…
  • Wait for a process to finish

    Is there any builtin feature in Bash to wait for a process to finish? The wait command only allows one to wait for child processes to finish. I would like to know if there is any way to wait for any process to finish before proceeding in any script. A mechanical way to do this is as follows but I would like to know if there is any builtin feature in Bash. while ps -p `cat $PID_FILE` > /dev/null; d

    Wait for a process to finish
    dynamicsoar
    dynamicsoar 2019/02/21
    “tail --pid=$pid -f /dev/null” まじか…
  • 1