fab-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Fab-user] bash variable substitution


From: Jeff Forcier
Subject: Re: [Fab-user] bash variable substitution
Date: Sat, 13 Jun 2009 11:57:54 -0400

Looks like we need to be backslash-escaping dollar signs, then. What's
going on is that when you call that run() statement, what really
happens is (and you can see this yourself with --show=debug):

    [localhost] run: /bin/bash -l -c "VAR=\"lol\" ; echo $VAR"

In this case, "$VAR" is interpreted at the top level (the level where
we are calling /bin/bash) and thus is empty. Backslash-escaping it
means that it is then only interpreted at the "inner" level, inside
the call to bash, where it works correctly:

    [localhost] run: /bin/bash -l -c "VAR=\"lol\" ; echo \$VAR"
    [localhost] out: lol

As this behavior is due to Fabric double-quoting your command as an
argument to bash, I think it makes sense to add this to the limited
escaping we do for run and sudo calls (which up till now was simply
escaping double-quotes). Thus, your original attempt will work as
expected (and you'll see the added backslash if you do --show=debug).

I've just pushed this change to master as 2dbe070.

Best,
Jeff

On Sat, Jun 13, 2009 at 11:47 AM, Vincent
Fretin<address@hidden> wrote:
> Hi,
>
> I've just tested trunk version, same problem.
> if you do:
>
> def echo():
>    run("VAR='myvar'; echo $VAR > afile")
>
> afile is empty.
>
> Regards
> Vincent
>
>
> On Fri, Jun 12, 2009 at 3:39 PM, Jeff Forcier<address@hidden> wrote:
>> Hi Vincent,
>>
>> As far as I know that should still work correctly; it's possible
>> you're seeing a bug that was fixed post-0.9a3, where there was a
>> chance of output simply being dropped and not displayed. If you're
>> able, I suggest grabbing the latest version of the code from Github or
>> git.fabfile.org, in which the issue has been fixed.
>>
>> Either way, I'll try to test out your below snippet with the latest
>> code sometime soon, in case there is another bug at work here :)
>>
>> Best,
>> Jeff
>>
>> On Fri, Jun 12, 2009 at 3:49 AM, Vincent Fretin<address@hidden> wrote:
>>> Hi,
>>>
>>> bash variable substitution worked in Fabric 0.1. With Fabric 0.9a3, it
>>> doen't work anymore
>>>
>>> def echo():
>>>    run("VAR='myvar'; echo $VAR")
>>>
>>> returns a blank line instead of myvar:
>>> [host] run: VAR='myvar'; echo $VAR
>>> Password for address@hidden:
>>>
>>> Done.
>>>
>>> Using bash variable was the only way I could find Fabric 0.1 to do the
>>> things I wanted.
>>> In fabric 0.9a3, I think I can find another way, but I have to adapt
>>> all my scripts.
>>>
>>> Regards
>>> --
>>> Vincent Fretin
>>>
>>>
>>> _______________________________________________
>>> Fab-user mailing list
>>> address@hidden
>>> http://lists.nongnu.org/mailman/listinfo/fab-user
>>>
>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]