- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: ksh script to set home directory
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2002 06:23 PM
08-21-2002 06:23 PM
==============================================
WHOAMI=`who am i|cut -d" " -f1`
echo $WHOAMI
cd ~$WHOAMI
pwd
output from Solaris:
========================
c950849
/home/oraadm/c950849
output on HP
===============================
c950849
cdh[3]: ~c950849: not found
/ora/admin
Could someone please advise how to achieve the Sun result on HP. Thankyou.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2002 06:27 PM
08-21-2002 06:27 PM
Re: ksh script to set home directory
What shell you using for login?
What is the login directory?
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2002 06:41 PM
08-21-2002 06:41 PM
Re: ksh script to set home directory
What shell you using for login?
/usr/bin/ksh
What is the login directory?
/ora/admin
More info:
I first login as c950849 to directory
/home/oraadm/c950849
I then su to oracle to directory
/ora/admin
I then run cdh and get
c950849
cdh[3]: ~c950849: not found
/ora/admin
Thanks Nigel.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2002 07:44 PM
08-21-2002 07:44 PM
Re: ksh script to set home directory
Does "grep c950849 /etc/passwd" give you any output?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2002 07:57 PM
08-21-2002 07:57 PM
Re: ksh script to set home directory
Please see output below:
>grep c950489 /etc/passwd
c950849:xVgnQ9xydh5/.:19622:200:Nigel McGuiness,,,:/home/c950849:/usr/bin/ksh
Please note that this works:
>cd ~c950849
Just that when I use the variable it doesn't.
eg.
>WHOAMI=`who am i|cut -d" " -f1`
>cd ~$WHOAMI
ksh: ~c950849: not found
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2002 09:40 PM
08-21-2002 09:40 PM
SolutionTilde substitution doesn't work with parameter substitution - the "~$" is taken as 2 seperate words and so that is why the output you are getting is "~c950849".
The way to get the substitution in is to use "eval" as follows:
WHOAMI=`who am i|cut -d" " -f1`
echo $WHOAMI
eval cd ~$WHOAMI
pwd
One more point - the "who am i" will return the original real user login so if you've logged in as "root" and done "su - c960849" you will still get the properties of "root".
If this isn't what you want then I would substitute in "whoami" which returns the current user login. But then again, if this is the case you can simply get to the home directory by using "cd" by itself!
I don't know exactly what you're trying to achieve but in any case I hope this has been of some help,
Ollie.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2002 09:59 AM
08-22-2002 09:59 AM
Re: ksh script to set home directory
directory is, just use the $HOME env variable.
If you're trying to get someone else's home
directory based on their user id, try something
like:
grep "^$username:" /etc/passwd | cut -d: -f6
or, if you're on NIS:
ypcat passwd | grep "^$username:" | cut -d: -f6
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2002 11:09 AM
08-22-2002 11:09 AM
Re: ksh script to set home directory
cd ~$WHOAMI
with
cd ~/$WHOAMI
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2002 05:11 PM
08-22-2002 05:11 PM
Re: ksh script to set home directory
Perfect. Thanks.
Gregory,
Works well too. Ollie's just a bit more elegant!
Tom,
WHOAMI=`who am i|cut -d" " -f1`
echo $WHOAMI
cd ~/$WHOAMI
pwd
gives me
c950849
cdh[3]: /ora/admin/c950849: not found
/ora/admin
This is because the home directory for c950849
is actually /home/c950849 whereas this is trying to take me to oracle's home directory and subdirectory c950849.