I have a shell script (let's say test.sh) which prints out 16 values on screen and sometimes error messages on screen (because of upstream hardware issues). I want to count the number of lines on the screen and then save only when I have valid outputs. I am unable to do the both at same time.
I am new to the shell scripting , so I did something pretty basic
./test.sh | tee -a output1.txt
A=./test.sh | wc -l
When I do this it doesn't save the length in A
./test.sh | tee -a output1.txt
A=./test.sh | wc -l