I am just learning the (very) basics of BASH.
while IFS= read -r line; do
...
done
The above is helpful when needing to skip commented (say by #) lines from a file. One particular implementation of the above I come across does this, however I don't understand it. The person who posted it didn't provide any explanation for the commands (maybe they are very simple indeed). I kept searching and found not-so-cryptic solutions, but I believe it shall be very good me to understand the following:
while read -r line; do
[[ $line = \#* ]] && continue
done < "$file"
My intuition is that $line = \#*
is checking the content of variable line and if it starts with # (# is a special character, thus needs \
), does something. The * is there to signify that anything might appear after the initial #. Just as in $rm -r *.pdf
say.
But why the [] ? And why double [ [] ] ?
Also, just to check: is BASH a combination of python and c++ in terms of code arrangement? Every instruction shall start of a new line, however if we want to have 2 instructions in row on the same line, they need to be delimited by a ; (thus emulating c/c++)? Thus the ... line; do
instructions?
Thank you!