initialization-actions icon indicating copy to clipboard operation
initialization-actions copied to clipboard

Escape Perl variable $1 in repair_old_backports to prevent 'unbound v…

Open kuldeepkk-dev opened this issue 3 months ago • 3 comments

Title: Fix: Escape Perl variable $1 in cloud-sql-proxy.sh to prevent 'unbound variable' error Description This PR resolves a shell execution error that occurs during the provisioning of Dataproc clusters using the cloud-sql-proxy.sh initialization action when set -u (or set -o nounset) is active.

🐛 Issue The repair_old_backports function in cloud-sql-proxy.sh uses a perl substitution command within double quotes:

perl -pi -e "s{...}{\$1 ...}g"

The shell (running with set -u) attempts to perform variable substitution on the Perl back-reference $1 before passing the string to the perl interpreter. Since no positional parameter $1 is passed to the shell function, this causes the script to fail with the error:

/etc/google-dataproc/startup-scripts/dataproc-initialization-script-1: line 176: $1: unbound variable

✅ Solution The fix involves triple-escaping the $1 within the double-quoted string:

# Corrected line 176:
perl -pi -e "s{...}{\\\$1 ...}g"

This ensures the string $1 is passed literally to perl, allowing perl to correctly interpret it as a reference to the first captured group, thus preventing the shell from attempting to interpret it as an unset shell variable.

kuldeepkk-dev avatar Nov 17 '25 19:11 kuldeepkk-dev