SHARE
TWEET

Untitled

quantumech May 18th, 2019 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top