66

I have a shell script that fails saying there's no such file or directory.

This error message seems clear to me, but when I post about it, I'm being asked to include the full and complete error message anyways.

What's the purpose of this? Why isn't "no such file or directory" good enough?

Return to FAQ index

0

2 Answers 2

191

A generic message like "No such file or directory" only says something about the specific error code that was returned, but nothing about where, why or how it happened.

The rest of the error message is vital for filling in the gaps. It's especially important to copy-paste everything exactly as it is, because even tiny changes in punctuation provide important information.

For example, consider these shell script error messages:

  1. : No such file or directory
  2. ./myscript: line 2: /tmp/myfile: No such file or directory
  3. ./myscript: line 2: '/tmp/myfile': No such file or directory
  4. ./myscript: line 2: *.jpg: No such file or directory
  5. bash: ./myscript: No such file or directory
  6. bash: /myscript: No such file or directory
  7. bash: ./myscript: /bin/bash: bad interpreter: No such file or directory

Here's what you may currently see:

No such file or directory

Here's what an experienced person sees:

  1. There's a leading colon. This script has DOS line terminators.

  2. There are two spaces before the file path. Leading whitespace has snuck into a variable (or it's actually a nonbreaking space).

  3. There are unexpected quotes around the file path. It's being misquoted.

  4. The file name contains a glob. The pattern doesn't match anything, or is misquoted.

  5. The line starts with bash:, so it's from the shell and not your script. The script may be in a different directory.

  6. There's a missing period. You tried to run . /myscript instead of ./myscript.

  7. It mentions a bad interpreter, indicating that the shebang has the wrong path to bash.

So please, always include full, unmodified, unabbreviated output, even if you don't see how it could possibly be relevant.

If you want to hide some information like file names or host names, please don't just edit the output to hide them. Instead, create a new test case with non-sensitive data, make sure it has the same problem, and make a post about that instead. See Minimal Reproducible Example.

0
15

To add up upon the existing answer in a more generic way:

What's the point of this? Why isn't "no such file or directory" good enough?

Because that's too broad to give a reliable diagnosis of the original problem.

We need to see a minimal reproducible example (referred to as [mre] in comments), to help about diagnosing the error messages. This includes

  • We need to see real code, command line expressions, configuration file entries, etc ...
  • We need to see all, and the verbatim error messages
  • Optimum is to provide a test case with an online compiler/shell engine

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .