2

I ran xdg-mime query filetype <file name> to check the MIME type of a file, and it failed. How can I print the error code (exit code) of the xdg-mime command?

I want to know what error happened:

  1. Error in command line syntax.
  2. One of the files passed on the command line did not exist.
  3. A required tool could not be found.
  4. The action failed.
  5. No permission to read one of the files passed on the command line.
  • Now I set XDG_UTILS_DEBUG_LEVEL=100, the out put is: Runing file -i "file name" and then the mime type is "application/octet-stream" (unknown file type) but no error code is given. – Amanda Mar 22 '11 at 2:55
7

In Bourne-derived shells (sh, ash, bash, dash, zsh...) the exit code of the last-run program is in the $? variable:

$ ls /no-such-file
ls: /no-such-file: No such file or directory
$ echo $?
2

So in this case, the exit code of ls is 2.

  • Thank you both! It's not an error here and the error code is 0. – Amanda Mar 22 '11 at 8:49
0

"application/octet-stream" (unknown file type)

is not an error message, it simply means that file does not know what your file contains. This could happen for encrypted files for example, they look so random that file is unable to print something more precise than "this is data".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.