Skip to content

Commit 5a1694e

Browse files
author
Daniel Bolton
committed
Add shell_quote to command string
1 parent 77d9961 commit 5a1694e

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

apin.pl

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/perl
2+
use 5.010;
23
use strict;
4+
use String::ShellQuote;
35
use warnings;
46

57
my $args = '-P ';
@@ -14,18 +16,23 @@
1416
elsif ( /^[~?]/ ) {
1517
$pattern .= $_;
1618
}
17-
elsif ( /^[\w-.]+$/ ) {
19+
elsif ( /^[\w\-\.=]+$/ ) {
1820
$packages .= $_ . ' ';
1921
}
2022

2123
} # end of @ARGV loop
2224

23-
my $cmd = "aptitude install ";
24-
$cmd .= $args . ' ' if $args;
25-
$cmd .= $packages . ' ' if $packages;
26-
$cmd .= "'$pattern'" . ' ' if $pattern;
25+
my $cmd = 'aptitude install ';
26+
$cmd .= $args . ' ' if $args;
27+
$cmd .= $packages . ' ' if $packages;
28+
$cmd .= "'$pattern'" . ' ' if $pattern;
2729

28-
print "\n$cmd\n\n";
30+
my $quoted = shell_quote $cmd;
31+
my $su_call = 'su -c ' . $quoted . ' root';
2932

30-
system "su root -c \"$cmd\" ";
33+
say "$su_call";
34+
35+
system " $su_call ";
36+
37+
exit 0;
3138

0 commit comments

Comments
 (0)