Skip to content

Instantly share code, notes, and snippets.

@pjxiao
Created June 28, 2012 06:38
Show Gist options
  • Save pjxiao/3009527 to your computer and use it in GitHub Desktop.
Save pjxiao/3009527 to your computer and use it in GitHub Desktop.
save in variable and display STDOUT / 標準出力を変数に保存しつつ表示する
#!/bin/bash
# 動きません☆
stdout_log=''
<command> |
while read -r line
do
$stdout_log="$stdout_log$line"
echo "$line"
done
@pjxiao
Copy link
Author

pjxiao commented Jun 28, 2012

パイプでつなげた while はサブシェルで実行されるため、while 文中の変数を参照することができない。
http://www26.atwiki.jp/ghostwind/pages/54.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment