From a17e7505ed0cf50ac9c21591f5f77dd32aba5820 Mon Sep 17 00:00:00 2001 From: cschantz Date: Sat, 7 Feb 2026 02:20:45 -0500 Subject: [PATCH] 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 --- lib/mysql-analyzer.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/mysql-analyzer.sh b/lib/mysql-analyzer.sh index ab110e5..3530e1e 100755 --- a/lib/mysql-analyzer.sh +++ b/lib/mysql-analyzer.sh @@ -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 }