How to check the number of terminals open from inside a shell script

Cameron Simpson cs at zip.com.au
Sat Oct 30 21:49:12 UTC 2010


On 29Oct2010 09:52, suvayu ali <fatkasuvayu+linux at gmail.com> wrote:
| On 29 October 2010 06:39, Mark Liggett <mliggett at btisystems.com> wrote:
| > You could add your script to the .bashrc file – this way the script would
| > run once when the user logs on.
| 
| I presume you meant ~/.bash_profile ? ~/.bashrc is sourced every time
| a user opens a terminal, whereas ~/.bash_profile is sourced every time
| a user logs in. This distinction however becomes redundant when the
| user always uses a text terminal to login. (as in no gui)

Not if they run a subshell. For example, a shell escape from an editor,
or a screen session, or ...

The number of bugs in the .bashrc suggestion is high. $ signs, dahses
instead of underscores, .bashrc instead of .bash_profile, presuming the
user users bash at all (I don't if I can help it, myself - zsh has
better facilities), not working at all anyway, since another login
wouldn't see the exported variable anyway, not actually looking at
terminals at all...

But the OP needs to clarify what he/she means by "number of open
terminals" (for this user? only showing in "who"? or other terminals?
etc) and whether that is actaully what they need or just what they
think _indicates_ what they actually need.

What he/she actually asks for is difficult to do properly. Hopefully it isn't
what they need.

Cheers,
-- 
Cameron Simpson <cs at zip.com.au> DoD#743
http://www.cskk.ezoshosting.com/cs/

My motto is, 'Do it my way or watch your butt.' -  Nathan Arizona


More information about the users mailing list