Ruby shell中提交消息的简单正则表达式测试

Ruby shell中提交消息的简单正则表达式测试,ruby,regex,git,shell,Ruby,Regex,Git,Shell,我刚接触Shell,需要移植一个用ruby编写的简单commit-msg钩子,我的问题就在regex测试中,有人能帮忙吗 这是ruby中的代码: #!/usr/bin/env ruby message_file = ARGV[0] message = File.read(message_file) $regex = /\[([A-Z]+)-\d+\](.)*/ if !$regex.match(message) puts "[ERROR] Please use the following

我刚接触Shell,需要移植一个用ruby编写的简单commit-msg钩子,我的问题就在regex测试中,有人能帮忙吗

这是ruby中的代码:

#!/usr/bin/env ruby
message_file = ARGV[0]
message = File.read(message_file)

$regex = /\[([A-Z]+)-\d+\](.)*/

if !$regex.match(message)
  puts "[ERROR] Please use the following pattern: '[ABC-123] lorem ipsum'"
  exit 1
end

在sh中,脚本将是

#!/bin/sh
if echo $1 | egrep -qv '\[([A-Z]+)-\d+\](.)*'; then
  echo "[ERROR] Please use the following pattern: '[ABC-123] lorem ipsum'"
  exit 1;
fi