rokkonet

PC・Androidソフトウェア・アプリの開発・使い方に関するメモ

標準入力あるいはコマンドライン引数からテキストファイルを受け取るシェルスクリプト

2018 Jul. 07.
2018 Apr. 28.

〈tailコマンドに渡す例〉
if [ -p /dev/stdin ]; then
   tail -
else
   tail $1
fi

〈readコマンドに渡す例〉
 function outputLine() {
   while read Line
   do
      echo $Line
   done < /dev/stdin
 }


if [ -p /dev/stdin ]; then
   cat -
else
   cat $1
fi | outputLine