Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Ruby shows two different outputs for variable

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

"\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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading