Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
How can we get a user's home directory for every iteration of "i" in the below script?
Script:-
for i in `cat UserList`
do
HomeDir= {This variable should get the value of the respective User's Home Directory in every iteration of "i" }
echo $HomeDir
done
How can we get a user's home directory for every iteration of "i" in the below script?
Script:-
for i in `cat UserList`
do
HomeDir= {This variable should get the value of the respective User's Home Directory in every iteration of "i" }
echo $HomeDir
done
Hope I'm clear.
Thanx in advance.
Can it be done using Environment Variable $HOME ...But how ??
Note: this really depends on what you are trying to do and why. The above would be more helpful if it included the username with each homedir... or whatever.
And the entire thing can be reduced to one awk-command if you are looking for all users (even all between a range of user IDs).
The benefit of using one awk command is that the file is read once (not once per name like above) and you spawn less resources to get the job done.
You would want to parse /etc/passwd but this seems like a really inefficient way to do it. Still:
Code:
for i in `cat UserList`
do
grep "$i" /etc/passwd | awk -F: '{print $6}'
done
Thanks for the reply . And yes I'm afraid even I think thats a long way approach , as there is ready variable available on Unix thats $HOME..... can we use it in any way in above script??
No we can't because it is only available to the user when they are logged in. And we are not logging in as each user (which would waste even more system resources).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.