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.

Required fields*

3
  • 3
    Better to use if [ -f "$file" ]; then .... Not a directory would return not only regular files but sockets and symlinks too. Commented Mar 13, 2017 at 19:29
  • @JRFerguson based on the OP's question I would say that including sockets and pipes would be a really bad idea. As for symlinks, those are implicitly included with ! -d already. Commented Mar 13, 2017 at 20:41
  • I used [ -f $file ] in my final script. Note the lack of quotation marks in the if condition. Almost everywhere I looked had quotation marks around $file, yet I had to delete them in order for my script to work. Commented Mar 14, 2017 at 8:07