Bash: How to get the home directory of a user in a variable
Sat Jul 28 17:30:50 EDT 2007
Not the clearest title...what I mean is, I was writing a Bash script like this:
SOMEONE=foo ... mv $SOMETHING ~$SOMEONE
only it kept failing with "~foo: No such file or directory". I had a look at the manual, but it wasn't terribly clear. In a nutshell, though, Bash wasn't doing the tilde expansion no matter what combination of braces and quotes tried.
Eventually, I came across a pirated copy of the ever-excellent Unix Power Tools, 3rd Ed. (mine's at work, or I'd've checked it a lot sooner), and it had a solution:
FINAL_RESTING_PLACE=$(/bin/bash -c "echo ~${SOMEONE}")I'm sure there must be a better way of doing this, though...Woot, any suggestions?