read line doubt
hi all...
In the below script how the read line will come to know about the first line of the file entered as argument... #!/bin/bash file1=$1 while read line do echo $line done < $file1 |
because on the last line, the file is being redirected into the loop upon which the while condition is dependent
|
Quote:
Code:
#!/bin/bash For more information, run "help while" at a command prompt: Code:
[user@machine:~]:help while |
I think that he's more concerned about the redirection.
The must-read for this is the 'REDIRECTION' section in the bash man page. What happens with the < $file1 at the end of the loop is that that file is fed into it, becoming effectively stdin for all purposes in the context of the loop. read consumes it because it read from stdin, but it could be any other command. That's why in these cases you must be specially careful with what you put inside the loop as well. |
All times are GMT -5. The time now is 10:14 AM. |