Assigning two variables with "#" using read in bash

How can I assign a string to a variable if it contains “#”.


while read var1 var2; do
    echo [$var1] [$var2]
done < "file.txt"


# var1


[#] [var1]

I am expecting it would be:

[#var1] []
[#] [var1]

The first data is being neglected and I don’t know why. How I can retrieve data with # in its prefix?

Source: shell

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.