"bash increment variable in while loop" Code Answer's
You're definitely familiar with the best coding language Whatever that developers use to develop their projects and they get all their queries like "bash increment variable in while loop" answered properly. Developers are finding an appropriate answer about bash increment variable in while loop related to the Whatever coding language. By visiting this online portal developers get answers concerning Whatever codes question like bash increment variable in while loop. Enter your desired code related query in the search bar and get every piece of information about Whatever code related question on bash increment variable in while loop.
bash increment variable in while loop
You are using USCOUNTER in a subshell, that's why the variable is not showing in the main shell.
Instead of cat FILE | while ..., do just a while ... done < $FILE. This way, you avoid the common problem of I set variables in a loop that's in a pipeline. Why do they disappear after the loop terminates? Or, why can't I pipe data to read?:
while read country _; do
if [ "US" = "$country" ]; then
USCOUNTER=$(expr $USCOUNTER + 1)
echo "US counter $USCOUNTER"
fi
done < "$FILE"
Note I also replaced the `` expression with a $().
I also replaced while read line; do country=$(echo "$line" | cut -d' ' -f1) with while read country _. This allows you to say while read var1 var2 ... varN where var1 contains the first word in the line, $var2 and so on, until $varN containing the remaining content.
All those coders who are working on the Whatever based application and are stuck on bash increment variable in while loop can get a collection of related answers to their query. Programmers need to enter their query on bash increment variable in while loop related to Whatever code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about bash increment variable in while loop for the programmers working on Whatever code while coding their module. Coders are also allowed to rectify already present answers of bash increment variable in while loop while working on the Whatever language code. Developers can add up suggestions if they deem fit any other answer relating to "bash increment variable in while loop". Visit this developer's friendly online web community, CodeProZone, and get your queries like bash increment variable in while loop resolved professionally and stay updated to the latest Whatever updates.