Advertisement
quantumech

Untitled

May 18th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.71 KB | None | 0 0
  1. # This is the first example of reading a file into a loop
  2. # The 'read' command is able to be used in a while loop because it
  3. # returns 'true' after is executes
  4. # The variable 'content' is set to the content of 'text.txt' because text from the 'cat' command is being piped into the 'read' command
  5. while cat text.txt | read content
  6. do
  7.     echo $content
  8. done
  9.  
  10. # This is the second example of reading a file into a loop
  11. # This example uses file redirection to input the contents of 'text.txt' into the while loop
  12. # The file input operator 'command < filename' treats the entire while loop 'code block' as 1 command and pipes the contents of 'text.txt' into it
  13. while read content
  14. do
  15.     echo $content
  16. done < script.sh
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement