0

The "canonical" example of usefulness of POSIX shell eval built-in is this:

>foo=10
>x=foo
>eval y='$'$x
>echo $y
10

But the POSIX shell standard says:

The eval utility shall construct a command by concatenating arguments together, separating each with a <space> character. The constructed command shall be read and executed by the shell.

Indeed, I can't find any examples of non-trivial (that is, whose results cannot be achieved simpler) usage of eval with such contatenation?

Please show me.

Mark Galeck
  • 5,671
  • 1
  • 23
  • 48
  • 2
    Voting to close as too broad. While many of the links in https://www.google.com/search?q=site%3Astackoverflow.com+shell+eval will be specific to `bash` or some other shell, there will be plenty of examples to amuse and enlighten you. – tripleee Jun 27 '16 at 05:18
  • @tripleee can you explain why you think this is "too broad"? The question is precise and specific. It serves to understand something not clear from the standard, not covered by example in the standard, and I did go over the example myself. – Mark Galeck Jun 27 '16 at 17:27
  • Mainly the "idle curiosity" language from https://stackoverflow.com/help/dont-ask - if you are trying to solve a concrete problem, what is it? If you would like to discuss, maybe post a separate question on [meta]. – tripleee Jun 27 '16 at 17:42
  • @tripleee I see your point, but I am going to respectfully disagree. It is not idle curiosity. I am trying to solve a concrete problem, which I cannot elaborate here, but for which, I have to perfectly understand `eval`. "Why some part of some manual is necessary and could not be omitted" is a very concrete problem to ask. – Mark Galeck Jun 27 '16 at 18:39
  • 1
    I do see from tripleee's comment, that in this link http://stackoverflow.com/questions/11065077/eval-command-in-bash-and-its-typical-uses there is an answer to my question. Because it is buried in there, I will simplify it here so maybe others can benefit: `y=$(eval echo \${$x})` – Mark Galeck Jun 27 '16 at 18:45

0 Answers0