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

Re: Resolved: Re: OT: Bash: what is eval doing here?



On 2022-06-12 at 07:57, rhkramer@gmail.com wrote:

> On Saturday, June 11, 2022 10:25:34 AM Greg Wooledge wrote:
> 
>> On Sat, Jun 11, 2022 at 09:54:17AM -0400, rhkramer@gmail.com
>> wrote:
>>> eval `ssh-agent`
> 
>> For the record, the command you've got here is written in a very 
>> antiquated way.  A better (as well as more modern) way to write it 
>> would be:
>> 
>> eval "$(ssh-agent)"
> 
> I am curious about the origin of the more modern syntax -- was it
> driven (or partially driven) by the possiblity of (a human) confusing
> the backticks for single quotes (like I did)?

I don't know the history myself (a brother of mine might, but I don't
know if he's up at this hour), but my guess would be more that it's
about other things - such as, for example, nesting.


The syntax (modulo quoting)

$ foo $(bar $(baz))

is unambiguous, but the syntax

$ foo `bar `baz``

is sufficiently ambiguous that it's not going to practically be possible
for the shell to determine what the writer intended to do.


There's a possibility that something like

$ foo `bar \`baz\``

might be supported and might work, but even if so, that would just mean
having to keep track of how many escaping backslashes you've used on
each backtick - and it would probably make managing quoting the
subshells even harder to get right. It'd be unwieldy at best, compared
to the explicit start-and-end markers that are involved with the $()
syntax.

-- 
   The Wanderer

The reasonable man adapts himself to the world; the unreasonable one
persists in trying to adapt the world to himself. Therefore all
progress depends on the unreasonable man.         -- George Bernard Shaw

Attachment: signature.asc
Description: OpenPGP digital signature


Reply to: