I need to check if it has data it works correctly if it is empty it fails.
#!/bin/bash
while read _mem
do
if [[ -s $_mem ]] ; then
echo "$_mem"
else
echo "The file is empty"
fi
done
I run it like this ./filechk.sh < stuff
If the file stuff has data it prints each line of the file. If it is empty it prints nothing. I think it has something to do with the fact that the read fails so the loop fails but when I change it to this.
#!/bin/bash
while read _mem
do
if [[ -s $_mem ]] ; then
echo "$_mem"
fi
done || echo "The file is empty"
That does not work either as even though the read fails it exits with 0.
Aucun commentaire:
Enregistrer un commentaire