Why is the number of lines in my bash output showing as 4 instead of 3?

  • Thread starter r0bHadz
  • Start date
In summary, the conversation discusses the use of the "ps -ly" command in bash to output three lines, which is then piped to the "wc -l" command to count the number of lines. Despite only seeing three lines, the output shows four lines. The individual then realizes they may have posted in the wrong forum and asks for the thread to be deleted.
  • #1
r0bHadz
194
17
TL;DR Summary
Using command ps -ly I get output of three lines
piping that output to wc -l it says that there are four lines. Why
In bash, I am writing the following:

ps - ly

this command gives me output of three lines

then I do:

ps -ly | wc -l

to read the number of lines. It says 4.

I clearly see that there are three lines. Thinking that there might be a new line possibly, I open export the command output to a file and open it in vim and no, there are just three lines.

I am wondering why the number is 4?
 
Computer science news on Phys.org
  • #2
hmm wrong forum maybe this should go to programming and computer science instead? Can I get a mod to help me out

edit: actually please delete this thread I have my answer now :) thank you
 
Last edited:

1. Why is the number of lines in my bash output showing as 4 instead of 3?

There could be a few reasons for this. One possibility is that your bash output includes a blank line, which is counted as a line. Another possibility is that your command is producing an extra line of output, such as an error message. Additionally, if you are using a tool or script to process your output, it may be adding an extra line.

2. How can I troubleshoot why my bash output is showing an extra line?

The first step would be to check the command or tool you are using to produce the output. Make sure it is not adding any extra lines of its own. You can also try using a different command or tool, or manually inspecting the output to see if there are any unexpected blank lines or error messages.

3. Is it possible for bash output to show a fractional number of lines?

No, bash output will always show a whole number of lines. If you are seeing a fractional number of lines, it is likely due to rounding or formatting in the program or tool you are using to display the output.

4. Can the number of lines in bash output change depending on the operating system or terminal being used?

Yes, it is possible for the number of lines in bash output to vary depending on the operating system or terminal being used. This could be due to differences in how the output is formatted or displayed, or variations in how commands are executed.

5. How can I ensure that my bash output always shows the correct number of lines?

To ensure that your bash output always shows the correct number of lines, it is important to carefully check your commands and any tools or scripts being used to process the output. You can also manually count the number of lines in your output to verify that it matches your expected result.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
15
Views
1K
Replies
15
Views
4K
  • Programming and Computer Science
Replies
2
Views
241
  • Electrical Engineering
Replies
6
Views
792
Replies
2
Views
2K
Replies
4
Views
571
  • Computing and Technology
Replies
15
Views
4K
  • Atomic and Condensed Matter
Replies
3
Views
733
Replies
3
Views
1K
  • Computing and Technology
Replies
22
Views
2K
Back
Top