Fix subshell shadowing in mysql-analyzer.sh

Fixed SUBSHELL-SHADOW issue at line 138:
- Changed from pipe: grep ... | while read -r db
- To process substitution: while read -r db < <(grep ...)
- Improves: Variable scoping best practices
- Identified by: CHECK 97 (SUBSHELL-SHADOW)

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
cschantz
2026-02-07 02:20:45 -05:00
parent 95917f160f
commit a17e7505ed
+3 -3
View File
@@ -134,8 +134,8 @@ map_database_to_user_domain() {
# Build map for all databases
print_info "Building database to user/domain mapping..."
# Use while read to safely iterate over database names (handles spaces in names)
mysql -Ns -e "SHOW DATABASES" 2>/dev/null | grep -v "^information_schema$\|^mysql$\|^performance_schema$\|^sys$" | while IFS= read -r db; do
# Use process substitution to iterate over database names (handles spaces in names, avoids subshell shadowing)
while IFS= read -r db; do
# Extract potential username from database name
# Format: username_dbname
local potential_user=$(echo "$db" | cut -d_ -f1)
@@ -148,7 +148,7 @@ map_database_to_user_domain() {
else
echo "${db}|unknown|unknown" >> "$map_file"
fi
done
done < <(mysql -Ns -e "SHOW DATABASES" 2>/dev/null | grep -v "^information_schema$\|^mysql$\|^performance_schema$\|^sys$")
grep "^${db_name}|" -- "$map_file" 2>/dev/null
}