![]() ![]() Now, execute the ls command on the /etc directory and then display the exit code: $ ls /etc ![]() Although, again, the information from exit code provides no real value to me. The exit code of 0 means that the ls command ran without issue. I have nothing in my home directory other than hidden files and directories, so nothing to see here, but the exit code doesn't care about anything but the success of the command's execution: $ ls Success is relative because the exit code only informs you that the script or command executed fine, but the exit code doesn't tell you whether the information from it has any value. Examples will better illustrate what I'm describing.įor one example, list files in your home directory. It tells you that your latest command or script executed successfully. Exit status 0Īn exit status of 0 is the best possible scenario, generally speaking. You might also receive a shell error message from Bash further describing the error, but the exit code and the shell error together should help you discover what went wrong. The displayed response contains no pomp or circumstance. It's simply a number. To display the exit code for the last command you ran on the command line, use the following command: $ echo $? It's time to look at examples of what generates error codes/statuses. A reserved error code is one that's used by Bash and you shouldn't create your own error codes that conflict with them.Įnough backstory. In this article, I explain the handful of reserved error codes, how they can occur, and how to use them to figure out what your problem is. For example, an exit code of 1 is a generic bucket for miscellaneous errors and isn't helpful at all. And yet, I also use exit codes to figure out where my problems are and why things are going wrong.Įxit codes are useful to an extent, but they can also be vague. It's sad, really, but I'm competent enough at copying and adapting found code that I can accomplish my required tasks. Oh sure, I can script and program a little in PHP, Perl, Bash, and even PowerShell (yes, I'm also a Windows administrator), but I could never make a living at programming because I'm too slow at writing code and trial-and-error isn't an efficient debugging strategy. I've studied BASIC, FORTRAN, and a few other languages both formally and informally, and I have to say that I am definitely not a programmer. It's hard for me to admit that, but it's true. ![]() Hopefully my use of the two terms will be clear to you. The terms are used interchangeably except in documentation. Note: You'll often see exit code referred to as exit status or even as exit status codes. Programmers use exit codes to help debug their code. Yet, you might never know about the code, because an exit code doesn't reveal itself unless someone asks it to do so. An exit code is a system response that reports success, an error, or another condition that provides a clue about what caused an unexpected result from your command or script. When you execute a command or run a script, you receive an exit code.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |