Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix double negative pandas

  • Loading branch information...
commit 53b9d008e5d828b84c71de499d7dcef4a6b68c97 1 parent 8170d7c
@holdenk authored
Showing with 3 additions and 3 deletions.
  1. +2 −2 Unicorn/Shell.pm
  2. +1 −1  t/shell.t
View
4 Unicorn/Shell.pm
@@ -15,9 +15,9 @@ sub fix_shell {
#Probably!
#Handle with [-e foo -e bar]
# http://www.pixelbeat.org/programming/shell_script_mistakes.html
- $rt =~ s/if\s*\[\s*\-e\s*(\w+?)\s*\-e\s*(\w+?)\s*\]\s*$/if [-e $1] || [\-e $2]/;
+ $rt =~ s/$\s*if\s*\[\s*\-e\s*(\w+?)\s*\-e\s*(\w+?)\s*\]\s*$/if [-e $1] || [-e $2]/;
#Double negative
-# $rt =~ s/\[\s*\!\-z\s*(\"\$\w*\")\]/SUP/;
+ $rt =~ s/$\s*if\s*\[\s*\!\-z\s*(\"\$\w*\")\]/if [$1]/;
#Check for cat pipe to grep
#i.e cat foo | grep baz
$rt =~ s/^\s*cat\s*(\w+)\s*\|\s*grep\s+([\w\"]+)\s*$/grep $2 < $1/
View
2  t/shell.t
@@ -5,6 +5,6 @@ use Unicorn::Shell qw( fix_shell check_shell);
is (fix_shell("fake","#!/bin/bash\nif [-e foo -e bar]"), "#!/bin/bash\nif [-e foo] || [-e bar]", "Expands -e works");
is (check_shell("fake","#!/bin/bash\nif [-e foo -e bar]"), 1, "Expands -e works");
is (fix_shell("fake","#!/bin/bash\nif [-e foo -f bar]"), "#!/bin/bash\nif [-e foo -f bar]", "Does not expand -e / -f");
-is (fix_shell("fake","#!/bin/bash\nif [!-z \"$foo\"]"), "#!/bin/bash\nif [\"\$foo\"]", "Removes double negatives");
+is (fix_shell("fake","#!/bin/bash\nif [!-z \"\$foo\"]"), "#!/bin/bash\nif [\"\$foo\"]", "Removes double negatives");
done_testing();
Please sign in to comment.
Something went wrong with that request. Please try again.