Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

6
  • It can be safe as long as the string being evaled is fixed (as it is here), but in that case why bother with eval? On the other hand, if the string is constructed dynamically, you need to take care to constrain how it's constructed to make sure it's safe. Commented Apr 15, 2021 at 10:10
  • @GordonDavisson My thinking is, since I printf the dynamic string then it should be safe regardless of what it contains. Am I wrong in this? Commented Apr 15, 2021 at 10:16
  • 2
    See softwareengineering.stackexchange.com/questions/311507/… Commented Apr 15, 2021 at 10:54
  • 1
    a='"; echo "hi' is a negative example. Commented Apr 15, 2021 at 14:25
  • 1
    @waltinator I don't understand. eval "$b" just prints "; echo "hi. I can see how eval "$a" is dangerous though. Commented Apr 15, 2021 at 18:17