__/ [ 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.
|
|