“while read line” is bash while loop which is used many times for processing data on the line basis. this really makes life easy, when we like to process data from a file on liine basis we can also do these things with help of for loop. But this can also be done with help of “while read line” in easy method. I am using it most of times for my one line scripts that used to do many things as scripts do.

Syntax for “while read line” in script or one line

while read line
while read line ; do commands ; commands; done

Let check how it works with some examples.Like sometime we need to check cron deploy for all users present on system

awk -F: '{print }' /etc/passwd| while read line ; do echo +++++++++Cron for +++++++++;crontab -u  -l ; done

This way we can able to get cron deploy by all Users present in /etc/passwd file”.

The second example, like we want to deploy bulk Users in Linux machine. This could be easily completed with help of “while read line” in small script.

    cat user_list | while read line
    echo passw0rd | passwd --stdin

So As per situation based there can so many use for this loop. I’ll try to add few more examples time to time for same.