How To Preserve Quotes In Bash Arguments

If you want to preserve quoting to pass shell arguments to a called command, use the four characters “$@” (including the double quotes) instead of the two characters $*
![]() |
If you want to preserve quoting to pass shell arguments to a called command, use the four characters “$@” (including the double quotes) instead of the two characters $*
## to add a single backslash in front of whatever char was matched
1 2 3 4 |
my $password = q#abc'A1r%Fgt&jh[-#; $password =~ s/(['])/\\$1/g; print qq#'$password'\n#; 'abc\'A1r%Fgt&jh[-' |
## to double whatever char was matched
1 2 3 4 |
my $password = q#abc'A1r%Fgt&jh[-#; $password =~ s/(['])/$1$1/g; print qq#'$password'\n#; 'abc''A1r%Fgt&jh[-' |
## to convert ‘ to ‘\” for shell execution
1 2 3 4 |
my $password = q#abc'A1r%Fgt&jh[-#; $passwordShell =~ s/(['])/$1\\$1$1/g; print qq#'$password'\n#; 'abc'\''A1r%Fgt&jh[-' |