How to close other shells except current?

I need a simple script to close other shells/sessions except the one I'm currently logged in. I'm stuck with this line:

ps -o pid,tty,comm | grep sh$

Which results in selecting the current shells.

For example:

 1346 136,0  sh
 1355 136,1  sh

I can use the tty command to know my current shell (pts). Then, I think I need a loop.

Read more here:

Content Attribution

This content was originally published by John Doe at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: