LOGNAME


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers LOGNAME
# 1  
Old 10-29-2010
LOGNAME

Code:
LOGNAME = 'id | awk '{begpos = index($0,"(") Endpos = index($
0,")") print substr($0,begpos+1,endpos-begpos-1) }'; export LOGNAME

-bash: syntax error near unexpected token `('

I am getting this error

Last edited by radoulov; 10-29-2010 at 04:44 PM.. Reason: Code tags, please!
# 2  
Old 10-29-2010
The script is too difficult to follow if we assume a Posix Shell.

What Shell are you using?
What Operating System and version are you running?

What answer do you need in the environment variable $LOGNAME ?
# 3  
Old 10-29-2010
I suppose that actually you want something like this:

Code:
LOGNAME="$(
  id | 
    awk '{ 
      begpos = index($0, "("); endpos = index($0,")") 
      print substr($0, begpos+1, endpos-begpos-1) 
      }'
    )" 
    
export LOGNAME

And you may try this command instead:

Code:
id -un

On Solaris use /usr/xpg4/bin/id.
# 4  
Old 10-29-2010
Hmm I wondered about the space either side of the first equal sign. Is this csh or something else?
# 5  
Old 10-29-2010
I suppose it's just wrong, the OP seems to be using bash, given the error message.

---------- Post updated at 09:57 PM ---------- Previous update was at 09:55 PM ----------

Actually, yes, those spaces could be a csh artifact Smilie
# 6  
Old 10-29-2010
Most versions of unix "login" set $LOGNAME for you.

I wonder what Operating System this is.


If it wasn't set (and we have a normal Shell) I'd be tempted to use:
Code:
LOGNAME=`who am i|awk '{print $1}'`
or
LOGNAME=$(who am i|awk '{print $1}')


OMG. -bash does indeed appear in post #1. Looks like the spaces are a typo. Also "id -un" is cool.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

5 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

UNIX $USER and $LOGNAME environment variables

I have some comments about a previously closed topic whose name is the same as above Omitted from the discussion was the situation with a "sudo command or sudo within a script". There is an inconsistency between systems. On some systems $LOGNAME is invariant, on others, on RedHat sudo... (3 Replies)
Discussion started by: lsatenstein
3 Replies

2. Shell Programming and Scripting

Unix $USER and $LOGNAME environment variables

Hi, I am wondering what is the difference between the USER and LOGNAME environment variables, and under what situations would they be different? I am using Ubuntu 8.04 32-bit and I do not have 'login' command to test it. (7 Replies)
Discussion started by: royalibrahim
7 Replies

3. AIX

How to make LOGNAME writeable? It is set as READONLY in .profile

LOGNAME variable is set as READONLY in .profile. I want to make it WRITEABLE so that I can modify the LOGNAME values programatically/throush shell programs. Thanks, Guru (1 Reply)
Discussion started by: gurubbc
1 Replies

4. Shell Programming and Scripting

Python and logname

How would i do this in python In bash i would do below and this would add the users logname to a file This write the logname ie James to test.txt But how would i do it in python this doesnt work below and ive tried different ways but cannot find an answer But this just writes $(logname) to... (4 Replies)
Discussion started by: dave100
4 Replies

5. HP-UX

logname error

when we log into HP servers randomly we will get the message "logname: could not get the login name" if we open another connection we can login we are running SSH 3.7 on OS B.11.23 this only happens on HP and only using ssh, I know there were problems like this on older ssh verisons but this... (0 Replies)
Discussion started by: dhlopomo
0 Replies
Login or Register to Ask a Question