mirror of
https://git.proxmox.com/git/pve-common
synced 2025-08-06 08:45:35 +00:00
add shellquote utility function
This commit is contained in:
parent
23dc9401bb
commit
762e322386
@ -687,4 +687,26 @@ sub random_ether_addr {
|
||||
return $mac;
|
||||
}
|
||||
|
||||
sub shellquote {
|
||||
my $str = shift;
|
||||
|
||||
return "''" if !defined ($str) || ($str eq '');
|
||||
|
||||
die "unable to quote string containing null (\\000) bytes"
|
||||
if $str =~ m/\x00/;
|
||||
|
||||
# from String::ShellQuote
|
||||
if ($str =~ m|[^\w!%+,\-./:@^]|) {
|
||||
|
||||
# ' -> '\''
|
||||
$str =~ s/'/'\\''/g;
|
||||
|
||||
$str = "'$str'";
|
||||
$str =~ s/^''//;
|
||||
$str =~ s/''$//;
|
||||
}
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
1;
|
||||
|
Loading…
Reference in New Issue
Block a user