It is currently Tue, 30 Nov 2021 17:53:30 GMT



 
Author Message
 how to get uid in Bourne Shell script?
hi everyone,

I'm writting a script which would use user's uid
as an identification key.  I can't find any handy
command that can return current user's uid number to stdout.
And it can't be found anywhere in FAQ.

Now I am writing a c code contains getuid() function.
I don't think this is a good solution.  Anybody
has a better idea?

Thanks.

Joe Yang



 Wed, 16 Sep 1998 03:00:00 GMT   
 how to get uid in Bourne Shell script?
hi everyone,

I'm writting a script which would use user's uid
as an identification key.  I can't find any handy
command that can return current user's uid number to stdout.
And it can't be found anywhere in FAQ.

Now I am writing a c code contains getuid() function.
I don't think this is a good solution.  Anybody
has a better idea?

Thanks.

Joe Yang



 Wed, 16 Sep 1998 03:00:00 GMT   
 how to get uid in Bourne Shell script?
hi everyone,

I'm writting a script which would use user's uid
as an identification key.  I can't find any handy
command that can return current user's uid number to stdout.
And it can't be found anywhere in FAQ.

Now I am writing a c code contains getuid() function.
I don't think this is a good solution.  Anybody
has a better idea?

Thanks.

Joe Yang



 Wed, 16 Sep 1998 03:00:00 GMT   
 how to get uid in Bourne Shell script?

How about id & cut out the uid?

{wallace}/home/seem$ id
uid=2001(seem) gid=200(staff)
{wallace}/home/seem$

Works in my sh.

--
+---
| Matthew See
| UNIX Systems Administrator
| BHP Information Technology
| Lvl 6, 120 Collins St, Melbourne VIC 3000, Australia
| Phone : +61 3 9652 7680
| Fax   : +61 3 9652 7134
| E-mail: see.matthew...@bhp.com.au
+---



 Thu, 17 Sep 1998 03:00:00 GMT   
 how to get uid in Bourne Shell script?

That is going to a lot of extra trouble!  Just read the man
page for id, and use the -u option:

   id -u userid

which will print only the id number.

Floyd

--
Floyd L. Davidson          Salcha, Alaska         fl...@tanana.polarnet.com



 Thu, 17 Sep 1998 03:00:00 GMT   
 how to get uid in Bourne Shell script?

The -u flag is not available on all flavours of Unix, for a more generic way use sed, ie:

uid=`id|sed -e "s/uid=//" -e "s/(.*//"`
echo "UID is $uid"

Peter Turnbull (pet...@deetya.gov.au)



 Fri, 18 Sep 1998 03:00:00 GMT   
 how to get uid in Bourne Shell script?
[...]

 > The -u flag is not available on all flavours of Unix, for a
 > more generic way use sed, ie:

 > uid=`id|sed -e "s/uid=//" -e "s/(.*//"`
 > echo "UID is $uid"

With a little change this works even for UnixWare with a
non-standard message catalogue. UnixWare will change the output
of the "id" command depending on the variable LC_MESSAGES or
LANG. This tells UnixWare to use the default message catalogue:

    uid=`LANG=C id | sed -e "s/uid=//" -e "s/(.*//"`
    echo "UID is $uid"

Heiner
--
     -------------------------------------------------------------
    / Heiner Steven  h...@bintec.de / The expressed opinions are  /
   / BinTec Computersysteme GmbH / mine, not BinTec's --       /
  / Willstaetter Str. 30 ------- ...even if they should be ;-)/
 / D-90449 Nuernberg    / priv.: hei...@hsysnbg.nbg.sub.org  /
------------------------------------------------------------



 Fri, 18 Sep 1998 03:00:00 GMT   
 how to get uid in Bourne Shell script?
: >Zhaohui Yang <jy...@opencon.com> wrote:
: >>
: >>I'm writting a script which would use user's uid
: >>as an identification key.  I can't find any handy
: >>command that can return current user's uid number to stdout.
: >>And it can't be found anywhere in FAQ.
: >>
: >>Joe Yang
: >
: >How about id & cut out the uid?
: >
: >{wallace}/home/seem$ id
: >uid=2001(seem) gid=200(staff)
: >{wallace}/home/seem$

: That is going to a lot of extra trouble!  Just read the man
: page for id, and use the -u option:

:    id -u userid

At least on HP-UX,  this only works for root.  For anyone else,
id -u and id -u userid return the same thing,  the uid of the
current user.

: which will print only the id number.

: Floyd

: --
: Floyd L. Davidson          Salcha, Alaska         fl...@tanana.polarnet.com

--
Dan Mercer
Reply To:  damer...@mmm.com

Opinions expressed herein are my own and may not represent those of 3M.



 Fri, 18 Sep 1998 03:00:00 GMT   
 how to get uid in Bourne Shell script?
You could use the id(1) command.

    id -u  gives the uid of the logged user

Dominic Fernandes



 Sat, 19 Sep 1998 03:00:00 GMT   
 how to get uid in Bourne Shell script?
How about:

id=`expr "\`id\`" : '[^(]*(\([^)]*\)'`

(just a thought)

In article <4joil9$...@junior.entwicklung.BinTec.DE>, heiner@panic says...



 Sat, 19 Sep 1998 03:00:00 GMT   
 how to get uid in Bourne Shell script?

See the id command's man page



 Sat, 26 Sep 1998 03:00:00 GMT   
 how to get uid in Bourne Shell script?
snip

try id -ru
real user ID returned.  
id -u
effective ID returned



 Sun, 27 Sep 1998 03:00:00 GMT   
 
   [ 12 post ] 

Similar Threads

1. getting environment variables from c shell using Bourne shell

2. A Solaris 8 (Bourne Shell) Scripting question, regarding a log rotation script

3. help in learning how to do Bourne shell scripts then converting them to csh scripts


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software