在 Linux 下,不管你是启动一个桌面程序也好,还是在控制台下运行命令,所有的程序在结束时,都会返回一个数字值,这个值叫做返回值,或者称为错误号 ( Error Number )。
在控制台下,有一个特殊的环境变量
Diagram1.png
eqn4.png
$
0
先随便执行个命令,比如像上面的 ls 某些文件,然后通过 echo $?,打印 $? 的值~
我们发现返回值是 0,这是什么意思呢?
只要返回值是 0,就代表程序执行成功了~
也就是说,如果 $? 变量的值不是 0 的话,就表示上一个命令在执行的过程中出错了。我们可以试着 ls 一个不存在的文件:
ls: 无法访问 linuxgem: 没有那个文件或目录
$ echo $?
2
这样,对于某些打印出一堆不熟悉的英文信息的命令,可以方便的看出它是否成功执行结束。
不过,每次都 echo $? 一下太累了,没关系,你可以把 $? 放在提示符里去:
[0]galeki@localhost ~ $
export PS1="[\$?]${PS1}"
那么如果返回的值不是 0,我们要怎么知道是那里出错了呢? 大多数的程序出错都会给出提示,如果没有提示的话,可以用
OS error code
这样就清楚了,原来是文件不存在~
错误对照表:
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code
"OS error code 100:
"OS error code 101:
"OS error code 102:
"OS error code 103:
"OS error code 104:
"OS error code 105:
"OS error code 106:
"OS error code 107:
"OS error code 108:
"OS error code 109:
"OS error code 110:
"OS error code 111:
"OS error code 112:
"OS error code 113:
"OS error code 114:
"OS error code 115:
"OS error code 116:
"OS error code 117:
"OS error code 118:
"OS error code 119:
"OS error code 120:
"OS error code 121:
"OS error code 122:
"OS error code 123:
"OS error code 124:
"OS error code 125:
"OS error code 126:
"OS error code 127:
"OS error code 128:
"OS error code 129:
"OS error code 130:
"OS error code 131:
"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;
"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"