I have a strange issue related to grep -v
queries. Allow me to explain:
To display connections I use who
:
$ who
harry pts/0 2016-12-08 20:41 (192.168.0.1)
james pts/1 2016-12-08 19:28 (192.168.0.1)
timothy pts/2 2016-12-08 02:44 (192.168.0.1)
The current tty
of my terminal is pts/0
$ tty
/dev/pts/0
$ tty | cut -f3-4 -d'/'
pts/0
I attempt to exclude my own connection using grep -v $(tty | cut -f3-4 -d'/')
. The expected output of this command should be who
, without my connection. However, the output is most unexpected:
$ who | grep -v $(tty | cut -f3-4 -d'/')
grep: a: No such file or directory
grep: tty: No such file or directory
I enclose the $(...)
in quotes and that seems to fix the "No such file or directory" issue. However, my connection is still printed even though my tty (pts/0
) should've been excluded:
$ who | grep -v "$(tty | cut -f3-4 -d'/')"
harry pts/0 2016-12-08 20:41 (192.168.0.1)
james pts/1 2016-12-08 19:28 (192.168.0.1)
timothy pts/2 2016-12-08 02:44 (192.168.0.1)
As of this point I have absolutely no idea why the grep
query is malfunctioning. It is greatly appreciated if someone could shed some light on this strange issue.
set -x
first... Then run your command and see what are you actually trying togrep
... – don_crissti 13 hours agogrep
ing "not a tty". How would you suggest I get around this? – perhapsmaybeharry 13 hours ago