diff --git a/lib/reference-db.sh b/lib/reference-db.sh index 25a5ce2..06adc68 100755 --- a/lib/reference-db.sh +++ b/lib/reference-db.sh @@ -169,8 +169,8 @@ build_databases_section() { local total_dbs=$($mysql_cmd -Ns -e "SHOW DATABASES" 2>/dev/null | grep -v "^information_schema$\|^mysql$\|^performance_schema$\|^sys$" | wc -l) local current=0 - # Use while read to safely iterate over database names (handles spaces) - $mysql_cmd -Ns -e "SHOW DATABASES" 2>/dev/null | grep -v "^information_schema$\|^mysql$\|^performance_schema$\|^sys$" | while IFS= read -r db; do + # Use process substitution instead of pipe to avoid subshell shadowing (fixes current variable loss) + while IFS= read -r db; do [ -z "$db" ] && continue current=$((current + 1)) show_progress $current $total_dbs "Indexing databases..." @@ -186,7 +186,7 @@ build_databases_section() { local table_count=$($mysql_cmd -Ns "$db" -e "SHOW TABLES" 2>/dev/null | wc -l) echo "DB|$db|$owner|$domain|$size_mb|$table_count" >> "$SYSREF_DB" - done + done < <($mysql_cmd -Ns -e "SHOW DATABASES" 2>/dev/null | grep -v "^information_schema$\|^mysql$\|^performance_schema$\|^sys$") finish_progress echo "" >> "$SYSREF_DB" @@ -411,8 +411,8 @@ build_domains_section() { build_wordpress_section() { echo "[WORDPRESS]" >> "$SYSREF_DB" - # Find all wp-config.php files and iterate safely (handles spaces in paths) - find "$SYS_USER_HOME_BASE" -name "wp-config.php" -type f 2>/dev/null | while IFS= read -r wp_config; do + # Find all wp-config.php files using process substitution (fixes subshell shadowing) + while IFS= read -r wp_config; do [ -z "$wp_config" ] && continue local wp_dir=$(dirname "$wp_config") @@ -469,7 +469,7 @@ build_wordpress_section() { # Format: WP|domain|owner|path|db_name|db_user|version|plugin_count|theme_count echo "WP|$domain|$username|$wp_dir|$db_name|$db_user|$version|$plugin_count|$theme_count" >> "$SYSREF_DB" - done + done < <(find "$SYS_USER_HOME_BASE" -name "wp-config.php" -type f 2>/dev/null) echo "" >> "$SYSREF_DB" }