From: Dietmar Maurer Date: Tue, 25 Oct 2011 09:36:28 +0000 (+0200) Subject: add shellquote utility function X-Git-Url: https://git.proxmox.com/?p=pve-common.git;a=commitdiff_plain;h=762e32238687f0bb7a2687e39fb7145502fadf40 add shellquote utility function --- diff --git a/data/PVE/Tools.pm b/data/PVE/Tools.pm index 4c4e259..78d7b9f 100644 --- a/data/PVE/Tools.pm +++ b/data/PVE/Tools.pm @@ -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;