LoginSignup
18
16

More than 5 years have passed since last update.

コマンド実行結果を、改めて1行ずつ扱いたい場合

Posted at
a.sh
#! /bin/sh

lines=`mount`

while read line
do
        if [[ $line =~ sda ]]; then
                echo $line
        fi
done <<END
$lines
END

何かのコマンドの実行結果を変数に入れて、
1行ずつ、改めて処理したいときの方法とか。

上記サンプルは、mountの実行結果を一旦変数に入れて、
改めて、sdaを含む行を1行ずつ探して、echoで表示しています。

上記サンプルだと、grepでやれ、っていう話ですが(

18
16
5

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
18
16