add shellquote utility function

This commit is contained in:
Dietmar Maurer 2011-10-25 11:36:28 +02:00
parent 23dc9401bb
commit 762e322386

View File

@ -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;