See the Bash Console: Output: What will happen if we don't pass any variable with the read command? I will also show an example of the Bash script that reads an input file line by line and prints each line with some appended text. With that loss of line-by-line interaction with the shell, we lose the main advantage of the interactive prompt: immediate feedback. Step 1: Using the pup utility (or command-line HTML parser of your choice): Step 2 (assuming the words variable is being passed along): Check out Software Carpentry's excellent guide to for-loops in Bash, CompCiv is a Stanford Journalism course taught by Dan Nguyen, # send the stream through a reverse filter, # filter out words with less than 4 characters, # send an email with the page's title and word count, Computational Methods in the Civic Sphere, Software Carpentry's excellent guide to for-loops in Bash, Software-Carpentry's guide to the Unix Shell, Fetch a list of ten 10+-letter words from nytimes.com headlines. echo “line contains somestring” Create a shell script called while.sh: The simplest way to read a file line by line is by using the input redirector in a while loop. Bash while Loop. Cool Tip: Make your Bash script interactive! do echo $ fileCont . What if a condition is False at first attempt? The bash while loop is a control flow statement that allows code or commands to be executed repeatedly based on a given condition. And…nothing. But when you have a big task in front of you, involving more than ten lines of code, then it's time to put that code into a shell script. The -r option to read command disables backslash escaping (e.g., \n, \t). The while construct allows for repetitive execution of a list of commands, as long as the command controlling the while loop executes successfully (exit status of zero). This is about as simple as you can make a for loop: Did that seem pretty worthless? Read File Using Bash Script You can also create a bash script and read any file line by line. How to loop, aka designing a program to do repetitive work for you. The general while read line construction that can be used in Bash scripts: The same construction in one line (easy to use on the Linux command line): As example lets print all users from the /etc/passwd file: You can change it to the more appropriate name, depending on the contents of a FILE. 0 Source: www.cyberciti.biz. The general while read line construction that can be used in Bash scripts: while read LINE do COMMAND done < FILE. However, if you're new to programming in any language, what might also be unclear is how working with data streams is different than working with loops. And we still have all the disadvantages: if we make a typo earlier in the block of commands between do and done, we have to start all over. No matter how many commands we pack inside a for loop, nothing happens until we hit the done keyword. Cette forme ne conserve pas les blancs en début et fin de ligne. / bin / bash while read line do echo-e "$ line \ n" done