RE: why is grep behaving this way ?

2007-03-05 Thread Kevin Ross
 Yes,
 
  There are lots of alternatives
  like :
  who | grep `id -un`
  who | grep bhasker
  or even i tried to do this !!!
  who  a
  grep `logname` a
  that WORKS 
  ONLY this command who | grep `logname` does not work !
  WHY ?
 

Here's another workaround:

NAME=`logname`;who|grep $NAME



-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



Re: why is grep behaving this way ?

2007-03-05 Thread Ron Johnson
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 03/05/07 12:47, Kevin Ross wrote:
 Yes,

  There are lots of alternatives
  like :
  who | grep `id -un`
  who | grep bhasker
  or even i tried to do this !!!
  who  a
  grep `logname` a
  that WORKS 
  ONLY this command who | grep `logname` does not work !
  WHY ?

 
 Here's another workaround:
 
 NAME=`logname`;who|grep $NAME

Defensive programming!

NAME=`logname`  who|grep $NAME

 
 
 

-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFF7GyVS9HxQb37XmcRAjCpAJ9HabvHbgRYDqmSo0wxUwMoN935pwCfWiGc
uSpLLw2HQrcz9XIxXRRrfsA=
=sSPG
-END PGP SIGNATURE-


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



why is grep behaving this way ?

2007-03-02 Thread Bhasker C V

I have logname command give me this output
[EMAIL PROTECTED] ~]$ logname
bhaskerv

and say i execute this command

[EMAIL PROTECTED] ~]$ echo `logname`
bhaskerv

till this it is all fine

BUT
[EMAIL PROTECTED] ~]$ who | grep `logname`
logname: no login name
Usage: grep [OPTION]... PATTERN [FILE]...
Try `grep --help' for more information.


is there anything i am doing wrong ?


Re: why is grep behaving this way ?

2007-03-02 Thread Salvatore Iovene
On Fri, Mar 02, 2007 at 03:07:37PM +0530, Bhasker C V wrote:
 [EMAIL PROTECTED] ~]$ who | grep `logname`
 logname: no login name
 Usage: grep [OPTION]... PATTERN [FILE]...
 Try `grep --help' for more information.

Weird. Consiedering that this works:

who | grep `whoami`

Where's the catch?

-- 
Salvatore Iovene
http://www.iovene.com


signature.asc
Description: Digital signature


Re: why is grep behaving this way ?

2007-03-02 Thread Håkon Alstadheim
Salvatore Iovene wrote:
 On Fri, Mar 02, 2007 at 03:07:37PM +0530, Bhasker C V wrote:
   
 [EMAIL PROTECTED] ~]$ who | grep `logname`
 logname: no login name
 Usage: grep [OPTION]... PATTERN [FILE]...
 Try `grep --help' for more information.
 

 Weird. Consiedering that this works:

 who | grep `whoami`

 Where's the catch?

   
I'm running SuSE, and can reproduce the problem here. Seems logname does
something weird when stdin is not your tty. Check this out:

[EMAIL PROTECTED]:0$ logname/dev/null
logname: no login name

My manual-page has nothing to say. Try looking at the source if you must.

-- 
Håkon Alstadheim 
spamtrap: [EMAIL PROTECTED] -- 1 hit  you are out



-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



Re: why is grep behaving this way ?

2007-03-02 Thread Matus UHLAR - fantomas
  On Fri, Mar 02, 2007 at 03:07:37PM +0530, Bhasker C V wrote:
  [EMAIL PROTECTED] ~]$ who | grep `logname`
  logname: no login name
  Usage: grep [OPTION]... PATTERN [FILE]...
  Try `grep --help' for more information.

On 02.03.07 11:27, H?kon Alstadheim wrote:
 I'm running SuSE, and can reproduce the problem here. Seems logname does
 something weird when stdin is not your tty. Check this out:
 
 [EMAIL PROTECTED]:0$ logname/dev/null
 logname: no login name
 
 My manual-page has nothing to say. Try looking at the source if you must.

I'd say that logname detects logged user by checking terminal of stdin file
handle...

However, that's logname feature, use whoami or different utility 
-- 
Matus UHLAR - fantomas, [EMAIL PROTECTED] ; http://www.fantomas.sk/
Warning: I wish NOT to receive e-mail advertising to this address.
Varovanie: na tuto adresu chcem NEDOSTAVAT akukolvek reklamnu postu.
(R)etry, (A)bort, (C)ancer


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



Re: why is grep behaving this way ?

2007-03-02 Thread Michael Marsh

On 3/2/07, Matus UHLAR - fantomas [EMAIL PROTECTED] wrote:

I'd say that logname detects logged user by checking terminal of stdin file
handle...


Yup:

$ echo | strace -o'|grep readlink' logname
readlink(/proc/self/fd/0, pipe:[5242235], 511) = 14

$ strace -o'|grep readlink' logname
readlink(/proc/self/fd/0, /dev/pts/7, 511) = 10

--
Michael A. Marsh
http://www.umiacs.umd.edu/~mmarsh
http://mamarsh.blogspot.com


--
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]




Re: why is grep behaving this way ?

2007-03-02 Thread Bhasker C V
Yes,

 There are lots of alternatives
 like :
 who | grep `id -un`
 who | grep bhasker
 or even i tried to do this !!!
 who  a
 grep `logname` a
 that WORKS 
 ONLY this command who | grep `logname` does not work !
 WHY ?


On Fri, 2007-03-02 at 12:16 +0200, Salvatore Iovene wrote:
 On Fri, Mar 02, 2007 at 03:07:37PM +0530, Bhasker C V wrote:
  [EMAIL PROTECTED] ~]$ who | grep `logname`
  logname: no login name
  Usage: grep [OPTION]... PATTERN [FILE]...
  Try `grep --help' for more information.
 
 Weird. Consiedering that this works:
 
 who | grep `whoami`
 
 Where's the catch?
 
-- 
Bhasker C V
Registered Linux user: #306349 (counter.li.org)
The box said Requires Windows 95, NT, or better, so I installed Linux.


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



Re: why is grep behaving this way ?

2007-03-02 Thread Mike McCarty

Bhasker C V wrote:

Yes,

 There are lots of alternatives
 like :
 who | grep `id -un`
 who | grep bhasker
 or even i tried to do this !!!
 who  a
 grep `logname` a
 that WORKS 
 ONLY this command who | grep `logname` does not work !
 WHY ?


Most likely because logname misbehaves when stdin is not a tty.

Mike
--
p=p=%c%s%c;main(){printf(p,34,p,34);};main(){printf(p,34,p,34);}
Oppose globalization and One World Governments like the UN.
This message made from 100% recycled bits.
You have found the bank of Larn.
I can explain it for you, but I can't understand it for you.
I speak only for myself, and I am unanimous in that!


--
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]




Re: why is grep behaving this way ?

2007-03-02 Thread cga2000
On Fri, Mar 02, 2007 at 04:37:37AM EST, Bhasker C V wrote:
I have logname command give me this output
[EMAIL PROTECTED] ~]$ logname
bhaskerv
 
and say i execute this command
 
[EMAIL PROTECTED] ~]$ echo `logname`
bhaskerv
 
till this it is all fine
 
BUT
[EMAIL PROTECTED] ~]$ who | grep `logname`
logname: no login name
Usage: grep [OPTION]... PATTERN [FILE]...
Try `grep --help' for more information.
 
is there anything i am doing wrong ?

bash man page:

  Each command in a pipeline is executed as a separate process (i.e.,
   in a subshell).

The problem appears to be that the subshell where `logname` executes is
not a login shell.

Here are a few commands I issued from the linux console that may help
clarify:

$ logname
  myuser

$ logname 12 | logname # redirect stdout to stderr
  myuser # 1st instance of logname
  logname: no login name # 2nd instance of logname

The 1st logname command is successful. 

The 2nd logname command executes in a subshell and returns the message
you reported.

$ logname | logname 2 /dev/null  # returns nothing

The 2nd instance of logname writes an error message to stderr and
nothing to stdout.

As a result,

$ who | grep `logname`

ends up as:

$ who | grep

.. resulting in a syntax error.

Another angle of approach is that the logname command can only return
the login name as long as the calling process added an entry to the utmp
file (see info coreutils logname) .. If not, it fails and displays the
logname: no login name message.  I guess it would not make much sense
having all subshells invoked during an interactive session create/remove
entries to/from the /var/run/utmp file.

Thanks,
cga


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]