I´m trying to count how many shell or terminal windows are currently running.
ps a|grep bash;
ps a|grep tty;
But it can be inaccurate.
To list them:
To count them:
You will need to subtract 1 from that number as it includes the top TTY header.
This all depends if you are wanting to count how many sub shells are running or if you are wanting to count how many terminal windows are open.
To count just the terminal windows you would need to use:
On my system there are currently six tty's available. I also have one terminal open pts/0 that has 4 processes running in the fg or bg.
If you want to take away the background child processes then just pipe to uniq:
You still have to subtract 1 for the header title of TTY, but you can further improve this by taking the tty's out altogether as it appears you don't care about those anyways.
That will give you an accurate count.
Thinking about it more 'ps -a' would work better and you can leave out the first grep.