2015-01-09 186 views
-2
[ "$#" -eq 3 ] || die "3 arguments required, $# provided"   
echo $1 | grep -E -q '^[0-9][0-9].0.[0-9][0-9].[0-9][0-9][0-9]' || die "Numerical drop number required, $1 provided"  
echo $2 | grep -E -q '^[0-9][0-9].0.[0-9][0-9].[0-9][0-9][0-9]' || die "Numerical drop number required, $2 provided" 

回答

0
#!/usr/bin/env ruby 

fail "3 arguments required, #{ARGV.length} provided" unless ARGV.length == 3 
fail "Numerical drop number required, #{ARGV[0]} provided" unless ARGV[0] =~ /^[0-9]{2}.0.[0-9]{2}.[0-9]{3}/ 
fail "Numerical drop number required, #{ARGV[1]} provided" unless ARGV[1] =~ /^[0-9]{2}.0.[0-9]{2}.[0-9]{3}/ 

# profit??? 
+0

嘗試'/^[0-9]{2}.0.[0-9]{2}.[0-9] {3} /'。 – Hauleth

+0

當然,我改變了它。我懷疑''應該逃脫,但我認爲這相當於發佈的內容。 – ihaztehcodez

0
#!/usr/bin/env ruby 

` 
[ "$#" -eq 3 ] || die "3 arguments required, $# provided"   
echo $1 | grep -E -q '^[0-9][0-9].0.[0-9][0-9].[0-9][0-9][0-9]' || die "Numerical drop number required, $1 provided"  
echo $2 | grep -E -q '^[0-9][0-9].0.[0-9][0-9].[0-9][0-9][0-9]' || die "Numerical drop number required, $2 provided" 
` 

:d

+0

哈,不錯:) –