My problem is, I want a script which reads content from a pipe, checks if it's empty and output it if not, as seen here:
#!/bin/bash
var=$(cat -)
if [ -n "$var" ]
then
echo "$var"
else
echo "Pipe was empty"
fi
The problem is, cat reads from stdin, if the pipe is empty. Is there any way to prevent cat from doing that? Or is cat the wrong tool to use here?