Home of user that is stored in var


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Home of user that is stored in var
# 1  
Old 10-26-2010
Home of user that is stored in var

I have a user name that is stored in variable $i
and i want to use that user's home dirctor in case command

something like this


find ~"$i" |while read p
do
case "$p" in
( ~"$i"/myDir )
echo "$p"
;;
(*)
esac
done

but it doesn't work

some help please

Last edited by radoulov; 10-26-2010 at 12:36 PM.. Reason: Code tags, please!
# 2  
Old 10-26-2010
Please define "doesn't work" like error messages or unexpected behavior.
Your script sample works fine with ksh.
# 3  
Old 10-26-2010
In ksh, eval runs your line through the ksh one more time:
Code:
$( eval echo ~$i )

or

$( echo echo ~$i | ksh )

or in your case:

eval find ~$i . . . | . . . .

You can go get it yourself from /etc/passwd's final field.

Last edited by DGPickett; 10-26-2010 at 12:48 PM..
This User Gave Thanks to DGPickett For This Post:
# 4  
Old 10-26-2010
it show :
find: '~jan44' : no such file or director

where jan44 is the value of the $i
and i have a user with name jan44 on my system " debian" and i use bash
# 5  
Old 10-26-2010
Eval isn't required with ksh but will fix this script when run by bash:
Code:
ihome=$(eval echo ~$i)
find $ihome |while read p
do
  case "$p" in
  ($ihome/myDir)
    echo "$p"
  ;;
  esac
done

This User Gave Thanks to jlliagre For This Post:
# 6  
Old 10-26-2010
it works Thanks
# 7  
Old 10-26-2010
Maybe I have an old ksh? Revision: 82.10.1.61

You can do the eval right on the find, saving much clutter.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to echo a value of a var stored in another variable?

I'm writing a shell script in AIX and using ksh. I have a scenario where I have a variable A which stores $B. so when i echo "$A" it prints $B But I wish to print value stored in var b ie. \a\dir\res\ I wish to store \a\dir\res\ in a third variable C. later I want to cd into that path :... (1 Reply)
Discussion started by: simpltyansh
1 Replies

2. UNIX for Dummies Questions & Answers

Switching from root to normal user takes me to user's home dir

Whenever i switch from root to another user, by doing su - user, it takes me to home directory of user. This is very annoying as i want to be in same dir to run different commands as root sometimes and sometimes as normal user. How to fix this? (1 Reply)
Discussion started by: syncmaster
1 Replies

3. Solaris

ssh private keys stored on home server

Where in the world are the ssh private keys stored on the home server? I know the public keys are renamed to authorized_keys under the /export/home//.ssh directory on the remote server. (1 Reply)
Discussion started by: jastanle84
1 Replies

4. Solaris

how to change /export/home/user dir to /home /user in solaris

Hi all i am using solaris 10, i am creating user with useradd -d/home/user -m -s /bin/sh user user is created with in the following path /export/home/user (auto mount) i need the user to be created like this (/home as default home directory ) useradd -d /home/user -m -s /bin/sh... (2 Replies)
Discussion started by: kalyankalyan
2 Replies

5. Red Hat

User's home directory

Hi, By default user's home directory will be /home/$user. I want to change it to /javauser/$user. How can I do it? Thanks Jeevan. (5 Replies)
Discussion started by: jredx
5 Replies

6. AIX

/home belongs to a user?

While doing a "little" clean up job, i noticed something weird... A ls -altr of my / showed this: drwxr-xr-x 1549 johcham grands 102400 Jan 28 13:13 home How can a user become the owner / modify the group of my /home??? any thoughts? Can i chown this back to bin:bin (i think that... (2 Replies)
Discussion started by: Stephan
2 Replies

7. Shell Programming and Scripting

home vs user

Hello, I am trying to find out all users who still have a home dir but do not exist anymore in /etc/passwd file. Here is what I did but I am getting the opposit of what I want. Any suggestion? for USAGERD in `find /home -type d -exec ls -d {} \;` do USAGER=${USAGERD##/*/}... (4 Replies)
Discussion started by: qfwfq
4 Replies

8. HP-UX

Where are SAM user templates stored?

Hey, new here, so be nice! I'm trying to write a little script to automate the user creation process on one of our boxes. But I would like to be able to use the templates that we have set up in SAM. Is the information in these templates stored in a file somewhere, that I can reference in my... (5 Replies)
Discussion started by: paqman
5 Replies

9. UNIX for Dummies Questions & Answers

Files still being created in /var/spool/mmdf/lock/home

Hi all I need help finding a process that is continuing to create files in the above area. There are three sub folder titled addr q.local and msg . I have already found a process called mmdf running and have used the kill command to stop this from running. I have also looked for sendmail or... (12 Replies)
Discussion started by: TeaMaker
12 Replies

10. UNIX for Dummies Questions & Answers

Locking in user to $HOME

Is there a very easy and configurable method to lock a user into their home directory? I've checked on chroot() methodology.....but i'm not to excited about copying around ( or symlinking) libraries..binaries....etc. Thought about altering the groups via chgrp...to only allow read access to... (1 Reply)
Discussion started by: thomas.jones
1 Replies
Login or Register to Ask a Question