如何在bash中打印文件名为stdin的文件内容?

时间:2014-11-30 00:51:58

标签: bash shell

是否有像cat这样的bash命令,除了它从stdin而不是第一个参数获取文件名?例如:

echo "/home/root/file.txt" | somecommand

cat /home/root/file.txt

的输出相同

2 个答案:

答案 0 :(得分:1)

找到答案:

xargs cat

例如:

echo "/home/root/file.txt" | xargs cat

答案 1 :(得分:0)

如果您期望的文件名没有空格:

#!/bin/bash    
read filename
cat $filename

read builtin shell命令将标量从stdin读入环境变量。

相关问题