我正在打开一个通过ARGV在运行时获取的文件:
File.open(ARGV[0]) do |f|
f.each_line do |line|
Run Code Online (Sandbox Code Playgroud)
找到匹配后,我将输出打印给用户.
if line.match(/(strcpy)/i)
puts "[!] strcpy does not check for buffer overflows when copying to destination."
puts "[!] Consider using strncpy or strlcpy (warning, strncpy is easily misused)."
puts " #{line}"
end
Run Code Online (Sandbox Code Playgroud)
我想知道如何在(ARGV [0])文件中打印出匹配行的行号.
使用print __LINE__
显示Ruby脚本中的行号.我已经尝试了许多不同的print __LINE__
字符串插值的变化,但#{line}
没有成功.有没有办法可以打印出文件中的行号?