Reputation: 7554
Is there a bash command like cat
except that it takes the filename from stdin rather than the first argument? For example:
echo "/home/root/file.txt" | somecommand
would have the same output as cat /home/root/file.txt
Upvotes: 1
Views: 240
Reputation: 7554
Found the answer:
xargs cat
For example:
echo "/home/root/file.txt" | xargs cat
Upvotes: 1
Reputation: 16185
If the filename that you're expecting doesn't have a space:
#!/bin/bash
read filename
cat $filename
The read builtin shell command reads tokens from stdin into environment variables.
Upvotes: 0