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.

10
  • 1
    Great answer - short, portable, safe. Thanks! Commented Oct 7, 2016 at 9:45
  • 2
    This is a great idea, but I have a couple of suggestions: Firstly quoting should be added both around "$1" and "$#" (see this great answer unix.stackexchange.com/a/171347). Secondly, echo is sadly non-portable (particularly for -n), so printf '%s\n' "$1" should be used instead.
    – joki
    Commented Jan 4, 2018 at 9:37
  • thanks @joki I worked with many different unix systems and I wouldn't trust echo -n either, however I am not aware on any posix system where echo "$1" would fail. Anyhow, printf is indeed more predictable - updated. Commented Jan 9, 2018 at 14:11
  • 2
    Alternatively: last() { shift $(($# - 1));printf %s "$1";}
    – Léa Gris
    Commented Nov 19, 2020 at 15:03
  • 1
    @MichałŠrajer i Think if you are the guy tasked to write scripts for that 40 years old legacy SCO Unix, you are likely to know your way with the man pages and printed manual because browsing stackoverflow with Mozaic is going to be quite challenging on its own.
    – Léa Gris
    Commented Dec 2, 2020 at 13:20