Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.
share|improve this question
    
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

2 Answers 2

up vote 0 down vote accepted

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.

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

"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".

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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