linux下命令行执行后的返回值-错误值

2018-01-26 10:31:51来源:网络收集作者:咖啡不加糖人点击

分享

[var1]

我们最开始学习的C语言中,主函数中int main()函数的最后总会加一个return 0;充当返回值,当初我们并不知道这个返回值的意义是什么,我们经常使用的是普通函数中的返回值,当函数执行一个任务时,函数执行完毕之后总会返回一个适当的值来告诉执行者该函数执行的情况


linux 下,在terminal下,控制台下运行命令,所有的命令在结束时,都会返回一个数字值,这个值即为返回值,每个返回值都对应着一个错误号,根据错误号我们可以大致推断这个函数执行的情况。另外在terminal下,有一个特殊的环境变量 $?,保存着前一个程序的返回值,我们可以试试:


[root@oldpan ~]# ls
lnmp1.4lnmp1.4.tar.gzlnmp-install.log
[root@oldpan ~]# echo $?
0

上面通过echo观察执行ls的返回值,发现是0,说明该命令执行成功,也就是说,如果 $? 变量的值不是 0 的话,就表示上一个命令在执行的过程中出错了。我们可以试着 ls 一个不存在的文件:


[root@oldpan ~]# ls aaa
ls: cannot access aaa: No such file or directory
[root@oldpan ~]# echo o $?
o 2

显然这里的返回值发生了变化,变为2,意味着上面的命令执行有问题。


如果觉得每次都需要 echo $? 比较麻烦我们可以将其放到提示符中:


[root@oldpan ~]# export PS1="[/$?]${PS1}"
[0][root@oldpan ~]# ls aaa
ls: cannot access aaa: No such file or directory
[2][root@oldpan ~]#

通过上面的命令可以再提示符的最前面看到上一次执行命令的返回值结果。
另外,我们可以通过perror 这个命令来查看错误的信息:


$ perror 2
OS error code 2:No such file or directory
错误对照表:
"OS error code 1:Operation not permitted"
"OS error code 2:No such file or directory"
"OS error code 3:No such process"
"OS error code 4:Interrupted system call"
"OS error code 5:Input/output error"
"OS error code 6:No such device or address"
"OS error code 7:Argument list too long"
"OS error code 8:Exec format error"
"OS error code 9:Bad file descriptor"
"OS error code10:No child processes"
"OS error code11:Resource temporarily unavailable"
"OS error code12:Cannot allocate memory"
"OS error code13:Permission denied"
"OS error code14:Bad address"
"OS error code15:Block device required"
"OS error code16:Device or resource busy"
"OS error code17:File exists"
"OS error code18:Invalid cross-device link"
"OS error code19:No such device"
"OS error code20:Not a directory"
"OS error code21:Is a directory"
"OS error code22:Invalid argument"
"OS error code23:Too many open files in system"
"OS error code24:Too many open files"
"OS error code25:Inappropriate ioctl for device"
"OS error code26:Text file busy"
"OS error code27:File too large"
"OS error code28:No space left on device"
"OS error code29:Illegal seek"
"OS error code30:Read-only file system"
"OS error code31:Too many links"
"OS error code32:Broken pipe"
"OS error code33:Numerical argument out of domain"
"OS error code34:Numerical result out of range"
"OS error code35:Resource deadlock avoided"
"OS error code36:File name too long"
"OS error code37:No locks available"
"OS error code38:Function not implemented"
"OS error code39:Directory not empty"
"OS error code40:Too many levels of symbolic links"
"OS error code42:No message of desired type"
"OS error code43:Identifier removed"
"OS error code44:Channel number out of range"
"OS error code45:Level 2 not synchronized"
"OS error code46:Level 3 halted"
"OS error code47:Level 3 reset"
"OS error code48:Link number out of range"
"OS error code49:Protocol driver not attached"
"OS error code50:No CSI structure available"
"OS error code51:Level 2 halted"
"OS error code52:Invalid exchange"
"OS error code53:Invalid request descriptor"
"OS error code54:Exchange full"
"OS error code55:No anode"
"OS error code56:Invalid request code"
"OS error code57:Invalid slot"
"OS error code59:Bad font file format"
"OS error code60:Device not a stream"
"OS error code61:No data available"
"OS error code62:Timer expired"
"OS error code63:Out of streams resources"
"OS error code64:Machine is not on the network"
"OS error code65:Package not installed"
"OS error code66:Object is remote"
"OS error code67:Link has been severed"
"OS error code68:Advertise error"
"OS error code69:Srmount error"
"OS error code70:Communication error on send"
"OS error code71:Protocol error"
"OS error code72:Multihop attempted"
"OS error code73:RFS specific error"
"OS error code74:Bad message"
"OS error code75:Value too large for defined data type"
"OS error code76:Name not unique on network"
"OS error code77:File descriptor in bad state"
"OS error code78:Remote address changed"
"OS error code79:Can not access a needed shared library"
"OS error code80:Accessing a corrupted shared library"
"OS error code81:.lib section in a.out corrupted"
"OS error code82:Attempting to link in too many shared libraries"
"OS error code83:Cannot exec a shared library directly"
"OS error code84:Invalid or incomplete multibyte or wide character"
"OS error code85:Interrupted system call should be restarted"
"OS error code86:Streams pipe error"
"OS error code87:Too many users"
"OS error code88:Socket operation on non-socket"
"OS error code89:Destination address required"
"OS error code90:Message too long"
"OS error code91:Protocol wrong type for socket"
"OS error code92:Protocol not available"
"OS error code93:Protocol not supported"
"OS error code94:Socket type not supported"
"OS error code95:Operation not supported"
"OS error code96:Protocol family not supported"
"OS error code97:Address family not supported by protocol"
"OS error code98:Address already in use"
"OS error code99:Cannot assign requested address"
"OS error code 100:Network is down"
"OS error code 101:Network is unreachable"
"OS error code 102:Network dropped connection on reset"
"OS error code 103:Software caused connection abort"
"OS error code 104:Connection reset by peer"
"OS error code 105:No buffer space available"
"OS error code 106:Transport endpoint is already connected"
"OS error code 107:Transport endpoint is not connected"
"OS error code 108:Cannot send after transport endpoint shutdown"
"OS error code 109:Too many references: cannot splice"
"OS error code 110:Connection timed out"
"OS error code 111:Connection refused"
"OS error code 112:Host is down"
"OS error code 113:No route to host"
"OS error code 114:Operation already in progress"
"OS error code 115:Operation now in progress"
"OS error code 116:Stale NFS file handle"
"OS error code 117:Structure needs cleaning"
"OS error code 118:Not a XENIX named type file"
"OS error code 119:No XENIX semaphores available"
"OS error code 120:Is a named type file"
"OS error code 121:Remote I/O error"
"OS error code 122:Disk quota exceeded"
"OS error code 123:No medium found"
"OS error code 124:Wrong medium type"
"OS error code 125:Operation canceled"
"OS error code 126:Required key not available"
"OS error code 127:Key has expired"
"OS error code 128:Key has been revoked"
"OS error code 129:Key was rejected by service"
"OS error code 130:Owner died"
"OS error code 131:State not recoverable"
"MySQL error code 132: Old database file"
"MySQL error code 133: No record read before update"
"MySQL error code 134: Record was already deleted (or record file crashed)"
"MySQL error code 135: No more room in record file"
"MySQL error code 136: No more room in index file"
"MySQL error code 137: No more records (read after end of file)"
"MySQL error code 138: Unsupported extension used for table"
"MySQL error code 139: Too big row"
"MySQL error code 140: Wrong create options"
"MySQL error code 141: Duplicate unique key or constraint on write or update"
"MySQL error code 142: Unknown character set used"
"MySQL error code 143: Conflicting table definitions in sub-tables of MERGE table"
"MySQL error code 144: Table is crashed and last repair failed"
"MySQL error code 145: Table was marked as crashed and should be repaired"
"MySQL error code 146: Lock timed out; Retry transaction"
"MySQL error code 147: Lock table is full;Restart program with a larger locktable"
"MySQL error code 148: Updates are not allowed under a read only transactions"
"MySQL error code 149: Lock deadlock; Retry transaction"
"MySQL error code 150: Foreign key constraint is incorrectly formed"
"MySQL error code 151: Cannot add a child row"
"MySQL error code 152: Cannot delete a parent row"

最新文章

123

最新摄影

闪念基因

微信扫一扫

第七城市微信公众平台