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:
- Error in command line syntax.
- One of the files passed on the command line did not exist.
- A required tool could not be found.
- The action failed.
- No permission to read one of the files passed on the command line.
Best Answer
In Bourne-derived shells (
sh
,ash
,bash
,dash
,zsh
...) the exit code of the last-run program is in the$?
variable:So in this case, the exit code of
ls
is 2.