Home > Net >  Ruby shows two different outputs for variable
Ruby shows two different outputs for variable

Time:10-12

I am simply running a tail -n1 command 2>/dev/null and the output for some strange reason is showing me two different things:

> masscan_progress
=> "rate:  0.00-kpps,  0.00% done,3586348854:03:28 remaining, found=0       \rrate:  3.49-kpps,  0.08% done,   2:07:20 remaining, found=3       \rrate:  3.48-kpps,  0.16% done,   1:02:57 remaining, found=6       \rrate:  3.49-kpps,  0.24% done,   0:42:18 remaining, found=10       \rrate:  3.49-kpps,  0.31% done,   0:31:58 remaining, found=14       \rrate:  3.49-kpps,  0.40% done,   0:24:59 remaining, found=20       \rrate:  3.49-kpps,  0.47% done,   0:21:15 remaining, found=23       \rrate:  3.49-kpps,  0.55% done,   0:18:05 remaining, found=30       \rrate:  3.48-kpps,  0.63% done,   0:15:53 remaining, found=35       \rrate:  3.49-kpps,  0.71% done,   0:15:50 remaining, found=36       \rrate:  3.49-kpps,  0.78% done,   0:15:58 remaining, found=40       \rrate:  3.48-kpps,  0.87% done,   0:15:44 remaining, found=42       \rrate:  3.49-kpps,  0.94% done,   0:15:52 remaining, found=42       \rrate:  3.48-kpps,  1.02% done,   0:15:54 remaining, found=48       \rrate:  3.48-kpps,  1.09% done,   0:15:53 remaining, found=50       \rrate:  3.47-kpps,  1.18% done,   0:15:43 remaining, found=52       \rrate:  3.48-kpps,  1.25% done,   0:15:52 remaining, found=57       \rrate: ...

but puts returns exactly what I'm looking for:

> puts masscan_progress
rate:  3.47-kpps, 85.98% done,   0:02:15 remaining, found=3305

As a result, additional commands that searches data from the masscan_progress variable doesn't see what I see in puts, but instead it sees the larger output.

I have actually never, ever seen this before and not quite sure why this is happening. Any pointers would be greatly appreciated.

CodePudding user response:

"\r" (the escape representing a single carriage return character) tells the terminal to return to the start of the same line; output after that will overwrite what was written on that line before.

  •  Tags:  
  • ruby
  • Related