LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-24-2003, 02:52 PM   #1
player_2
Member
 
Registered: Aug 2003
Posts: 57

Rep: Reputation: 15
Unhappy Scripting help -- pathname expansion


I'm currently writing a script to help automate the task of adding accounts to our web server. This script will obviously need to run as root, and at one point I need to create a symlink in the new user's home directory. I don't want to hardcode /home into the script, so I tried using ~$1 (tilde) with no luck. It seems that the tilde expansion is actually a feature of bash, and though the command will expand to "ln -s /www/newuser ~newuser/www", the tilde will not be expanded to "/home/", which causes ln to complain that there is no such directory as "~newuser". Is there any way to retrieve the location of a user's home directory without using the tilde, or trick bash into expanding the tilde into the proper path (usually /home/)?

Any help appreciated. Thanks.
 
Old 08-24-2003, 03:07 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
You could grep and cut the passwd file:
grep "^rossy:" /etc/passwd| cut -d: -f6

However you may be able to achieve this without your script using hte /etc/skel directory. It depends on what you want to do.
 
Old 08-25-2003, 03:12 AM   #3
dharmender_rai
Member
 
Registered: Aug 2002
Location: Pune,India
Posts: 39

Rep: Reputation: 15
Hi,
$HOME variable would server your purpose.

-- Dharmender Rai
 
Old 08-25-2003, 05:03 PM   #4
player_2
Member
 
Registered: Aug 2003
Posts: 57

Original Poster
Rep: Reputation: 15
david_ross:

Thanks, but I wanted to avoid grepping /etc/passwd... but if it's necessary, I guess I have no choice. I don't think /etc/skel could do what I need; every user needs a different (similar, but different) symlink.

dharmender_rai:

$HOME would involve su'ing to the new user. That's ugly, and would then involve su'ing back to root to complete the rest of the script.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
pathname in ps command kaplan71 Linux - General 1 10-31-2005 12:57 PM
Determine absolute pathname aecaudel Programming 5 09-19-2005 01:06 AM
Replacing All Instances of a pathname with another in Vi Editor kaplan71 Linux - General 1 06-30-2005 03:54 PM
setting pathname for input file in C++ microsoft/linux Programming 27 05-09-2005 09:36 PM
openOffice template directory - what is the pathname? TSynergy Linux - Software 4 10-11-2004 09:53 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:49 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration