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.

4
  • 7
    eval for indirect reference is overkill, not to mention bad practice, and a huge security concern (the value is not quote in echo or outside $(). Bash has a builtin syntax for indirect references, for any var: ! So last="${!#}" would use the same approach (indirect reference on $#) in a much safer, compact, builtin, sane way. And properly quoted.
    – MestreLion
    Commented Aug 7, 2011 at 16:28
  • See a cleaner way to perform the same in another answer.
    – Palec
    Commented Oct 17, 2014 at 11:23
  • @MestreLion quotes are not needed on the RHS of=.
    – Tom Hale
    Commented Jun 11, 2019 at 7:15
  • 1
    @TomHale: true for the particular case of ${!#}, but not in general: quotes are still needed if content contains literal whitespace, such as last='two words'. Only $() is whitespace-safe regardless of content.
    – MestreLion
    Commented Jun 18, 2019 at 21:23