I am a new guy for bash shell. I am confused by the below script.
#!/bin/bash
input=name.csv
while IFS=',' read -r Family_name First_name
do
echo $Family_name
echo $First_name
done < $input
Intuitively, I thought the done is some kind of boundary marker that told you the while field is over.
Here it shows that done can take data from a variable. so what is the meaning/function of done in the while loop? Thanks.
Intuitively, I thought the done is some kind of boundary maker that told you the while field is over.
Correct; done ends a while-loop (or for-loop or similar).
Here it show that done can take the data from a variable.
No; the < $input (meaning < name.csv) is a redirection being applied to the whole while-loop. So it's the while-loop as a whole, not the done specifically, that takes input from name.csv.
Intuitively, I thought the done is some kind of boundary maker that told you the while field is over.
That's true. done is certainly a part of the while loop itself. The syntax is:
while list-1; do list-2; done
Here it show that done can take the data from a variable
The input redirection < is not specific to done keyword alone; rather it's for the entire loop and thus any input read from any statements from list-1 or list-2 would read from the file $input.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With