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.

5
  • 1
    Looks portable to me. On the other hand, will break for example on a filename containing a newline. Commented Oct 12, 2010 at 17:31
  • 1
    To improve further, replace echo "$1" with printf "%s\n" "$1" (same with the second echo). echo may interpret backslashes inside its arguments. Commented Oct 12, 2010 at 17:52
  • Again, you're right! Really, the behavior of echo command in zsh is different from bash.
    – hluk
    Commented Oct 12, 2010 at 18:29
  • 1
    Strictly speaking, under POSIX behaviour of echo is undefined if arguments contain backslashes. However, it is defined under XSI extension (namely, echo should interpret the escape sequences). But both bash and zsh are soo far even from POSIX compliance... Commented Oct 12, 2010 at 19:58
  • Sorry, but I don't see the point. I already provided an answer as a script with more features that this and it doesn't need to be used within a shell script.
    – dhardy
    Commented Oct 13, 2010 at 15:43