小编nan*_*z9l的帖子

如何通过ARGV打印我正在使用的文件的行号?

我正在打开一个通过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}没有成功.有没有办法可以打印出文件中的行号?

ruby printing file line argv

6
推荐指数
1
解决办法
3616
查看次数

标签 统计

argv ×1

file ×1

line ×1

printing ×1

ruby ×1