On Wed, Jan 02, 2002 at 08:34:25PM -0600, Jamie Ostrowski wrote:
>
>
>
>
> I am trying to write a shell script that takes the first argument
> from the command line as the user to whom a file is placed in their home
> directory. I can't seem to get this to run. Normally, it wouldn't be a big
> deal, you'd just do
>
> cp filename /home/$1
>
> but what throws a monkey wrench into the works is that there are
> several different home partitions some users are in home, others in
> home1,home2,home3, etc. and the following doesn't work:
>
> cp filename ~${1}/
>
> because it interprets the ~ as a character rather than an operator.
>
> Anyone have any ideas how I can get around this? Everytime I try to
> run? Seems you can't combine the ~ with a variable.
I assume your trying this in bash as your shell. If you are at
all familar with tcsh you might want to use tcsh, since ~ works
as expected in tcsh. The following script worked for me.
#!/bin/tcsh
cp foo ~${1}/
If its a long script and you already know perl, I would use that.
If its pretty short, tcsh works ok.
Oh, wait I knew there had to be a Bourne way to do it. Try this:
#!/bin/sh
this_home=`eval echo ~$1/`
cp foo $this_home
--
Jim Crumley |Twin Cities Linux Users Group Mailing List (TCLUG)
crumley at fields.space.umn.edu |Minneapolis/St. Paul, Minnesota
Ruthless Debian Zealot |http://www.mn-linux.org/
Never laugh at live dragons |Dmitry's free,who's next? http://faircopyright.org