Gary Gary - 10 months ago 76
Bash Question

While..Do with multiple conditions in shell

I need to read a file line by line until end of file, or a blank line is encountered. I have the following code in a shell script which does not work:

while read line
do
commands
done < file.prop || $line == ""


Can this be done?

Answer Source

Yes, this could be done easily with the break command.

while read line
do
    if [ "$line" == "" ]; then
        break
    else
        # commands
    fi
done < file.prop
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download