0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

シェルスクリプト グループコマンド

0
Last updated at Posted at 2019-11-28

{} で囲んだリストはグループコマンドとなり、複合コマンドとなる。

グループコマンドを使わない場合

それぞれのコマンドでリダイレクトしなければならない。

group-example1.sh
echo "group" > example1.log
pwd >> example1.log
date >> example1.log
グループコマンドを使う場合

最後のリダイレクトですべての標準出力がリダイレクトされる。

group-example2.sh
{
  echo "group"
  pwd 
  date
} > example2.log
group-result2.sh
group
/home/blueskyarea/work2
Thu Oct 10 11:01:34 JST 2019

サブシェルと違って、同一プロセス上で動作する。
リダイレクトは必要なくても、なんらかのまとまったコマンドの塊であることを明示するのに便利。

0
1
0

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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?