I've got a program that needs to access a file in the ~/etc/ directory.
This program currently accesses it like so:
file_path = File.expand_path("~#{ENV['USER']}/etc/#{filename}")
. . but that environment variable just looks hideous in there, at least
to me. In Perl, I'm used to using getpwuid() instead of $_ENV['user'].
Is there some equivalent to that in Ruby, or am I stuck with ENV['USER']?
--
CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ]
Kent Beck: "I always knew that one day Smalltalk would replace Java. I
just didn't know it would be called Ruby."
|
|
0
|
|
|
|
Reply
|
perrin (1253)
|
3/20/2008 7:05:12 AM |
|
On Thu, 2008-03-20 at 16:05 +0900, Chad Perrin wrote:
> I've got a program that needs to access a file in the ~/etc/ directory.
> This program currently accesses it like so:
>
> file_path = File.expand_path("~#{ENV['USER']}/etc/#{filename}")
>
> . . . but that environment variable just looks hideous in there, at least
> to me. In Perl, I'm used to using getpwuid() instead of $_ENV['user'].
> Is there some equivalent to that in Ruby, or am I stuck with ENV['USER']?
>
require 'etc'
Etc.getpwuid.dir
works for me...
--
Alex
|
|
0
|
|
|
|
Reply
|
alex605 (521)
|
3/20/2008 8:27:03 AM
|
|
On Thu, Mar 20, 2008 at 05:27:03PM +0900, Alex Young wrote:
>
> On Thu, 2008-03-20 at 16:05 +0900, Chad Perrin wrote:
> > I've got a program that needs to access a file in the ~/etc/ directory.
> > This program currently accesses it like so:
> >
> > file_path = File.expand_path("~#{ENV['USER']}/etc/#{filename}")
> >
> > . . . but that environment variable just looks hideous in there, at least
> > to me. In Perl, I'm used to using getpwuid() instead of $_ENV['user'].
> > Is there some equivalent to that in Ruby, or am I stuck with ENV['USER']?
> >
>
> require 'etc'
> Etc.getpwuid.dir
>
> works for me...
Hallelujah. That's exactly what I wanted. Thank you much.
I don't know why this wasn't working:
> ri getpwuid
Nothing known about getpwuid
--
CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ]
Kent Beck: "I always knew that one day Smalltalk would replace Java. I
just didn't know it would be called Ruby."
|
|
0
|
|
|
|
Reply
|
perrin (1253)
|
3/20/2008 4:50:49 PM
|
|
On Fri, 2008-03-21 at 01:50 +0900, Chad Perrin wrote:
> On Thu, Mar 20, 2008 at 05:27:03PM +0900, Alex Young wrote:
> >
> > On Thu, 2008-03-20 at 16:05 +0900, Chad Perrin wrote:
> > > I've got a program that needs to access a file in the ~/etc/ directory.
> > > This program currently accesses it like so:
> > >
> > > file_path = File.expand_path("~#{ENV['USER']}/etc/#{filename}")
> > >
> > > . . . but that environment variable just looks hideous in there, at least
> > > to me. In Perl, I'm used to using getpwuid() instead of $_ENV['user'].
> > > Is there some equivalent to that in Ruby, or am I stuck with ENV['USER']?
> > >
> >
> > require 'etc'
> > Etc.getpwuid.dir
> >
> > works for me...
>
> Hallelujah. That's exactly what I wanted. Thank you much.
>
> I don't know why this wasn't working:
>
> > ri getpwuid
> Nothing known about getpwuid
I get:
> qri getpwuid
nil
Same problem. Documentation seems to be rather hit-and-miss all round
these days, but I haven't got any time to contribute to help. I was
lucky with this - I managed to trawl it out of the depths of my memory
from a few months ago, when I needed something else in Etc.
--
Alex
|
|
0
|
|
|
|
Reply
|
alex605 (521)
|
3/20/2008 5:16:15 PM
|
|
Hi,
At Thu, 20 Mar 2008 16:05:12 +0900,
Chad Perrin wrote in [ruby-talk:295141]:
> I've got a program that needs to access a file in the ~/etc/ directory.
> This program currently accesses it like so:
>
> file_path = File.expand_path("~#{ENV['USER']}/etc/#{filename}")
File.expand_path("~/etc/#{filename}")
--
Nobu Nakada
|
|
0
|
|
|
|
Reply
|
nobu (580)
|
3/20/2008 9:16:02 PM
|
|
On Fri, Mar 21, 2008 at 06:16:02AM +0900, Nobuyoshi Nakada wrote:
> Hi,
>
> At Thu, 20 Mar 2008 16:05:12 +0900,
> Chad Perrin wrote in [ruby-talk:295141]:
> > I've got a program that needs to access a file in the ~/etc/ directory.
> > This program currently accesses it like so:
> >
> > file_path = File.expand_path("~#{ENV['USER']}/etc/#{filename}")
>
> File.expand_path("~/etc/#{filename}")
Amazing -- and confusing. I could swear I actually tried that and it
didn't work out for me. I guess I must have dreamed that.
--
CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ]
Phillip J. Haack: "Productivity is not about speed. It's about velocity.
You can be fast, but if you're going in the wrong direction, you're not
helping anyone."
|
|
0
|
|
|
|
Reply
|
perrin (1253)
|
3/21/2008 11:22:30 PM
|
|
It's 4 years late I know, but I found this:
http://stackoverflow.com/a/4194280/20654
File.expand_path('~')
So the next guy that reach this via google get the right answer ;)
On Friday, March 21, 2008 5:22:30 PM UTC-6, Chad Perrin wrote:
> On Fri, Mar 21, 2008 at 06:16:02AM +0900, Nobuyoshi Nakada wrote:
> > Hi,
> >
> > At Thu, 20 Mar 2008 16:05:12 +0900,
> > Chad Perrin wrote in [ruby-talk:295141]:
> > > I've got a program that needs to access a file in the ~/etc/ directory.
> > > This program currently accesses it like so:
> > >
> > > file_path = File.expand_path("~#{ENV['USER']}/etc/#{filename}")
> >
> > File.expand_path("~/etc/#{filename}")
>
> Amazing -- and confusing. I could swear I actually tried that and it
> didn't work out for me. I guess I must have dreamed that.
>
> --
> CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ]
> Phillip J. Haack: "Productivity is not about speed. It's about velocity.
> You can be fast, but if you're going in the wrong direction, you're not
> helping anyone."
|
|
0
|
|
|
|
Reply
|
oscarryz (2)
|
8/11/2012 1:00:16 AM
|
|
On Friday, March 21, 2008 5:22:30 PM UTC-6, Chad Perrin wrote:
> On Fri, Mar 21, 2008 at 06:16:02AM +0900, Nobuyoshi Nakada wrote:
> > Hi,
> >
> > At Thu, 20 Mar 2008 16:05:12 +0900,
> > Chad Perrin wrote in [ruby-talk:295141]:
> > > I've got a program that needs to access a file in the ~/etc/ directory.
> > > This program currently accesses it like so:
> > >
> > > file_path = File.expand_path("~#{ENV['USER']}/etc/#{filename}")
> >
> > File.expand_path("~/etc/#{filename}")
>
> Amazing -- and confusing. I could swear I actually tried that and it
> didn't work out for me. I guess I must have dreamed that.
>
> --
> CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ]
> Phillip J. Haack: "Productivity is not about speed. It's about velocity.
> You can be fast, but if you're going in the wrong direction, you're not
> helping anyone."
On Friday, March 21, 2008 5:22:30 PM UTC-6, Chad Perrin wrote:
> On Fri, Mar 21, 2008 at 06:16:02AM +0900, Nobuyoshi Nakada wrote:
> > Hi,
> >
> > At Thu, 20 Mar 2008 16:05:12 +0900,
> > Chad Perrin wrote in [ruby-talk:295141]:
> > > I've got a program that needs to access a file in the ~/etc/ directory.
> > > This program currently accesses it like so:
> > >
> > > file_path = File.expand_path("~#{ENV['USER']}/etc/#{filename}")
> >
> > File.expand_path("~/etc/#{filename}")
>
> Amazing -- and confusing. I could swear I actually tried that and it
> didn't work out for me. I guess I must have dreamed that.
>
> --
> CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ]
> Phillip J. Haack: "Productivity is not about speed. It's about velocity.
> You can be fast, but if you're going in the wrong direction, you're not
> helping anyone."
|
|
0
|
|
|
|
Reply
|
oscarryz (2)
|
8/11/2012 1:00:30 AM
|
|
|
7 Replies
46 Views
(page loaded in 0.101 seconds)
Similiar Articles: How to get home directory of specified user? - comp.unix ...Hi, I need get full path name for a specified user's directory. For example, I need get the full path name "/home/John/temp" for "~John/temp". Is th... LDAP user does not have home directory after log into local ...... customary to create a user's home directory ... macros for path,names, concat, and output export - comp.soft-sys ... LDAP user does not have home directory after log into ... How to determine path of executable? - comp.unix.programmer ...So you should put configuration files in the current user home directory (or if it's a ... Please help - How to get the Path of Executable of a Windows ... Dear Experts, I ... Displaying file full Path - comp.databases.filemakerHow to get home directory of specified user? - comp.unix ... Hi, I need get full path name for a specified user's ... This will delete the specified directory, all files ... Transferring Data folder to Win7 -- no luck yet - comp.mail.eudora ...To more or less > replicate the laptop's path, I created a User ... of the shortcut is normally the path to the directory ... exportfs file, it contains: - /export/home ... can't get real path - comp.unix.solaris... pfexec /home/myuser/patchadd patchadd: can't get real path I got. ... allowing a user to run with euid=0 an executable in a directory ... How to get the file path from HTML ... Getting current path during Make execution - comp.sys.hp.hpux ...Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER ... Windows ... How to get the current directory path c# winfows application Hi I created an application in c:\inetpub ... Please help with path problem - comp.unix.programmerMY PATH FILE ===== set mail=$HOME/Mail/mbox set prompt="<\!> $USER at `hostname ... Please help - How to get the Path of ... logging in slow or su from root to normal user - comp.unix.solaris ...... no errors in messages I would look into the configuration of your user's home ... True , but the test user I created had a local home directory !! G Unable to login as oracle user - comp.unix.shell"su -" tries to change to the new user's home directory; try leaving off the ... worth posting it's worth archiving > X-No-HTML: yes > User-Agent: nn/6.7.3 > Path ... User Home Directory,Java Home Directory,Find User Home Directory ...User Home Directory in Java - Online code to find user home directory, how to get home ... C:\convert\rajesh\completed>java UserHomeExample User Home Path: C ... .net - Getting the path of the home directory in C#? - Stack OverflowOkay, I've checked Environment.SpecialFolder, but there's nothing in there for this. I want to get the home directory of the current user in C#. 6/26/2012 12:42:51 AM
|