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.

15
  • 10
    Don't forget to quote all the stuff. If you don't understand why, try your program on a file a b (two spaces between a and b, SO eats one of them). Commented Oct 12, 2010 at 17:27
  • 1
    also try this on "/" it turns into "///"
    – George
    Commented Jun 28, 2012 at 22:12
  • 43
    the only POSIX solution so far that does not require you to write and compile an executable since readlink and realpath are not POSIX Commented Jun 29, 2013 at 12:49
  • 36
    I used function realpath { echo $(cd $(dirname $1); pwd)/$(basename $1); } to make myself a realpath command (currently accepted answer) on OS X. Thanks! Commented Jun 20, 2014 at 19:13
  • 1
    I used this method to define log filenames for scripts: LOG=$(echo $(cd $(dirname $0); pwd)/$(basename $0 .sh).log) Commented Sep 12, 2014 at 13:53