In bash, how do I count the number of lines in a variable? December 28, 2022 by Tarik Quotes matter. echo "$var" | wc -l