Home Messages Index
[Date Prev][Date Next][Thread Prev][Thread Next]
Author IndexDate IndexThread Index

Re: bash scripts: using ~<username>

  • Subject: Re: bash scripts: using ~<username>
  • From: Roy Schestowitz <newsgroups@xxxxxxxxxxxxxxx>
  • Date: Mon, 25 Sep 2006 12:48:06 +0100
  • Newsgroups: comp.os.linux.misc
  • Organization: schestowitz.com / ISBE, Manchester University / ITS / Netscape / MCC
  • References: <450db030$0$75040$14726298@news.sunsite.dk> <slrnegrco0.huh.danSPANceswithTRAPcrows@clairissa.localdomain> <450e44b9$0$75038$14726298@news.sunsite.dk> <iij2u3-qcb.ln1@xword.teksavvy.com> <450ec6f1$0$75028$14726298@news.sunsite.dk>
  • Reply-to: newsgroups@xxxxxxxxxxxxxxx
  • User-agent: KNode/0.7.2
__/ [ Angel Tsankov ] on Monday 18 September 2006 17:17 \__

>>>>> When typed at the bash prompt, ~<username> is expanded to
>>>>> the
>>>>> home
>>>>> directory of the specified user. [Why can'] I use this
>>>>> construct in
>>>>> scripts? Or, if I can, then how?
>>>>
>>>> Works for me:
>>>>
>>>> clairissa:~$ cat temp.sh
>>>> #!/bin/bash
>>>> cd ~guest
>>>> pwd
>>>> clairissa:~$ ./temp.sh
>>>> /home/guest
>>>>
>>>> ...maybe you'd better post an example of how it doesn't work
>>>> for you,
>>>> with the exact command that's getting executed.  Remember,
>>>> when
>>>> debugging shell scripts, "set -x" can give you a whole lot of
>>>> information.
>>>
>>> Here's how it does not work:
>>>
>>> #~/bin/bash
>>> echo ~$1              # prints ~<username> to stdout
>>
>>   To do that requires two levels of evaluation, so use eval:
>>
>> eval "echo ~$1"
>>
>>  To store the directory in a variable:
>>
>> eval "dir=~$1"
> 
> What if $1 contains space?

Oh, disregard my last post please. I was viewing this thread from
C.O.L.questions, so had a partial view.

[Date Prev][Date Next][Thread Prev][Thread Next]
Author IndexDate IndexThread Index