Get username in script

how would i go about getting the username of the person currently logged in, and then using the username in a shell script? i've tried variations of
user=whoami , 'whoami' , $whoami , and none of the above work :frowning: lol
I'd like to get the username to then mount a network share such that the command would be,
mount_afp afp://username@dc.fqdns.edu/username /Users/username/Desktop/Home

any help on how to accomplish this would be IMMENSELY appreciated :] thanks

try this

export user=`eval whoami`
or export user=$(whoami)
echo $user

assuming one of these methods works, would that then allow me to execute a command such as..
mount_afp afp://$user@dc.fqdns.edu/$user /Users/$user/Desktop/Home
?

thanks :]

/* edit */ the second method worked, export user=$(whoami)
when i try: mount_afp afp://$user@dc.fqdns.edu/$user /Users/$user/Desktop/Home
i get this error:

=\ google doesn't help much.

I am not sure of mounting devices, but following the unix syntax you could try

mount_afp afp://${user}@dc.fqdns.edu/${user} /Users/${user}/Desktop/Home

do let me know if it works?

mm..i believe the problem is it wants the password? the command is supposed to be setup as afp://username:password@dc.fqdn.edu/.... but if the computers already logged in to active directory, itd be nice if the password wasn't required. otherwise there would have to be some form of input (i'm guessing) to get the password?
=\

If you are talking about retreiving the passwords from unix box then forget it because in unix the passwords are stored in the encrypted format which even the administrators cant retreived.

for further reference you could try this link.

http://www.hmug.org/man/8/mount_afp.php

no, i dont mean retrieving passwords.. i mean prompting the user to enter their password and using that in the shell script. except i'm unsure how i'd like to go about this or if i should just try some crazy concotion of applescript/shell script..maybe use a shell script to execute an applescript. lol thanks for your help though :]

you could try the command like this

read password

this should prompt for the user to enter the password.

If the above was your question, then

echo $LOGNAME

Which platform? whoami command is not available at all platforms, try `who am i` instead.