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.

3
  • 2
    See this comment attached to an older identical answer. Commented Jul 13, 2012 at 12:21
  • 1
    The simplest portable solution I see here. This one has no security problem, @DennisWilliamson, the quoting empirically seems to be done right, unless there is a way to set $# to an arbitrary string (I don’t think so). eval last=\"\${$#}\" also works and is obviously correct. Don’t see why the quotes are not needed.
    – Palec
    Commented Oct 17, 2014 at 11:47
  • 1
    For bash, zsh, dash and ksh eval last=\"\${$#}\" is fine. But for csh and tcsh use eval set last=\"\${$#}\". See this example: tcsh -c 'eval set last=\"\${$#}\"; echo "$last"' arg1 arg2 arg3.
    – oHo
    Commented Jul 22, 2017 at 21:11