6
5

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.

引数に$(cat)を指定し標準入力を受け取る(echo コマンドなど)

Last updated at Posted at 2016-07-31

こんにちは。
コマンド引数にて標準入力を受け取るようにするには、cat コマンドの助けを借りると良いようです。そのままでは標準入力を受け取らないコマンド(echo など)に用います。

echo コマンド

$ echo "hello" | echo $(cat)
"hello"

set コマンド

$ echo 1 2 3 | set $(cat); echo $3 $2 $1
3 2 1

シェルスクリプト1

$ echo 1 2 3 | sh -c 'w=$(cat); echo $w'
1 2 3

複数行の各行を受け取る

複数行の標準入力の各行を受け取る例です。

$ which -a realpath | realpath $(cat)
/usr/local/Cellar/coreutils/9.4/bin/grealpath
/bin/realpath
  1. 参考:「標準入力も受け取れるシェルスクリプト(catコマンド使用)

6
5
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
6
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?