env variables with spaces

Net Llama! netllama
Thu Mar 1 07:46:12 PST 2007


On Tue, 27 Feb 2007, Bill Campbell wrote:

> On Tue, Feb 27, 2007, Net Llama! wrote:
>> I'm running into an annoying problem.  I'm taking the output from 'env'
>> and dumping it to a file (/tmp/env.out), and then running 'source
>> /tmp/env.out'.  The problem is that some of the variables in env output
>> have values assigned to them with spaces, such as:
>> FOO=release debug
>>
>> When source hits this, it gets confused and assumes that the ' debug'
>> portion is something separate from the value of FOO, and barfs:
>> bash: release: command not found
>>
>> Anyone have any suggestions how to get around this?  thanks
>
> Wrap all variables in double quotes.
>
> env | sed 's/=\(.*\)/="\1"/' > /tmp/env.out
> . /tmp/env.out
>
> This doesn't take care of escaping double quotes in the value of
> the variables.  That's left as an exercise for the student.

Thanks Bill, this works perfectly.

-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lonni J Friedman                        netllama at linux-sxs.org
LlamaLand				http://netllama.linux-sxs.org



More information about the Linux-users mailing list