I want to pipe the output of one command to another script. In this other script I want to check whether the input was empty or just consists of spaces. If this is the case, I'll ignore it. Otherwise, I want all the input to be forwarded to another few commands.
For more clarity, I'll run something like cat input.txt | ./script.sh where input.txt looks like
line 1
line 2
line 3
and script.sh currently looks like:
read input_text
if [ -z "$input_text" ]
# ignore emtpy input
then exit 0
else
# do something here with the input
fi
The problem is that in this scenario, the first line of the input "line 1" is read into the input_text variable and therefore not forwarded with the rest of the input (which then solely consists of lines 2 and 3) into the code following after else.
So, how can I first check whether the input consists of more than just empty spaces and then forward the whole input to another command?