bug-bash
[Top][All Lists]
Advanced

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

Re: Using 'eval'


From: Pierre Gaston
Subject: Re: Using 'eval'
Date: Tue, 26 Jan 2010 15:36:57 +0200

On Tue, Jan 26, 2010 at 1:27 PM, Gerard <gerard@seibercom.net> wrote:
> This is probably a dumb question; however, I have a question
> regarding 'eval'.

> eval foo -a -b
eval will execute foo -a -b.

> eval $(foo -a -b)

foo -a -b will run before eval is executed, the output of foo will
replace the $( ).
ie if foo -a -b prints "echo hello" then the command executed will be
"eval echo hello"  which execute echo hello, and it will print hello

the difference with or without eval is that the expansion are done 2 times:

var=foo foo=bar;echo '$'$var
after the expansion $var is replace by it's value and the command executed:
echo '$'foo which prints '$foo'

var=foo foo=bar;eval echo '$'$var
after the expansion $var is replace by it's value and the command executed:
eval echo $foo
eval will do the expansion quote removal a second time and the command
executed by eval will be:
echo bar which prints "bar"




reply via email to

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