Most of the answers focused on an integer / line and spacing issue, which is fine, but your code looks so unified that IMO should be completely reinstalled. Let's say the idea is to process the lines until one line matches the regular expression 'test':
while read line; do if [[ "$line" =~ test ]] && break
Of course, this can be simplified if you use text processing tools such as sed:
sed -e '/test/,$d'
source share