Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symbolic errno to String

Tags:

bash

errno

Is there a command-line tool that will take a symbolic errno such as EINVAL and print the corresponding string, Invalid argument?

I would like to avoid having to find that EINVAL is value 22 on my system and then using$ perror 22.

Ideally I could write something like

$ errorcommand EINVAL
Invalid argument
$

like image 595
Flame Avatar asked Feb 07 '10 18:02

Flame


2 Answers

On my corporate box /usr/include wasn't available. So I put this portable simple solution (if you have Python) into my init files. You can torture it into a one-liner if you wish:

function strerror () {                                                         
    python -c "import os, errno; print(os.strerror(errno.$1))"                  
}                                                                              
like image 131
Leo Avatar answered Sep 17 '22 05:09

Leo


At least for Ubuntu (12.04 and later, to my certain knowledge), there's an errno utility you can easily install via apt-get install errno.

$ errno 98
EADDRINUSE 98 Address already in use
$ errno EINVAL
EINVAL 22 Invalid argument
like image 34
jdzions Avatar answered Sep 20 '22 05:09

jdzions