Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # This is the first example of reading a file into a loop
- # The 'read' command is able to be used in a while loop because it
- # returns 'true' after is executes
- # The variable 'content' is set to the content of 'text.txt' because text from the 'cat' command is being piped into the 'read' command
- while cat text.txt | read content
- do
- echo $content
- done
- # This is the second example of reading a file into a loop
- # This example uses file redirection to input the contents of 'text.txt' into the while loop
- # 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
- while read content
- do
- echo $content
- done < script.sh
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement