will try to write to file or directory ending at the first space in the variable. In addition, if $WP_DIRECTORY contains single quote mark, then the remaining part after the first space of the $WP_DIRECTORY will be executed instead of launcher.sh as designed.
I think the best way to handle issues like this is to do something like this:
SHELL_ENCODED_WP_DIRECTORY="$(printf "%s" "$WP_DIRECTORY" | sed "s/'/'\x22'\x22'/")"
SHELL_ENCODED_SP_PATH="$(printf "%s" "$SP_PATH" | sed "s/'/'\x22'\x22'/")"
echo "WP_BOX='$SHELL_ENCODED_WP_DIRECTORY'" source '"'$SHELL_ENCODED_SP_PATH/bin/launcher.sh'"' >> "$WP_DIRECTORY/box-run.sh"
Similar tweaks would be needed for other parts that generate new shell scripts. Other parts can just use double quotes around the variables. I also used source instead of . above to make it more readable. You already have bash shebang so you might as well use more readable bash features.
The install script contains various parts that cannot handle spaces in variable
$WP_DIRECTORY
correctly.For example:
will try to write to file or directory ending at the first space in the variable. In addition, if
$WP_DIRECTORY
contains single quote mark, then the remaining part after the first space of the$WP_DIRECTORY
will be executed instead of launcher.sh as designed.I think the best way to handle issues like this is to do something like this:
Similar tweaks would be needed for other parts that generate new shell scripts. Other parts can just use double quotes around the variables. I also used
source
instead of.
above to make it more readable. You already havebash
shebang so you might as well use more readablebash
features.