【问题标题】:Simple Regex test in shell for commit message用于提交消息的 shell 中的简单正则表达式测试
【发布时间】:2014-10-11 13:20:19
【问题描述】:

我是 Shell 新手,我需要移植一个用 ruby​​ 编写的简单 commit-msg 钩子,我的问题正是在正则表达式测试上,有人可以帮忙吗?

这是 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

【问题讨论】:

    标签: ruby regex git shell


    【解决方案1】:

    在 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
    

    【讨论】:

      猜你喜欢
      • 2015-06-30
      • 2019-09-25
      • 1970-01-01
      • 2019-05-25
      • 1970-01-01
      • 2014-03-29
      • 2012-08-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多