1
0

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 1 year has passed since last update.

Bash で複数のバックグラウンドプロセスを for ループで起動する

Last updated at Posted at 2020-08-19

Bash を使ってワンライナーの for ループで X window の glxgears& を使ってバックグラウンドでたくさん起動しようとしたら、なんかうまくいかなかったのでメモ。

結論

; の代わりに & を使うこと。

最初に試した方法

for ii in `seq 1 10`; do glxgears &; done

for ループを回して & で複数起動しようと思ったら以下のようなエラーが出る。

bash: syntax error near unexpected token `;'

解決した方法

for ii in `seq 1 10`; do glxgears & done

どうやら & のあとに ; を入れているのがまずかったらしい。

余談

Bash ではなく Zsh を使っていれば

for ii in `seq 1 10`; do glxgears & done
# だろうが
for ii in `seq 1 10`; do glxgears &; done
# だろうが

どちらも問題なく動く

参考リンク

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?