Looking at the man pages for cp, I only found that the command exits with 0 when copy succeeds with no error, and with a number greater than 0 on any error. However I couldn't find any detailed description on specific exit codes mapped to specific cases. Is there such a description anywhere, is it even standardized, or each Unix/Linux distribution has its own exit code set for different scenarios?
Depending on our shell, exit code 255 might mean that the returned exit code is outside of the 0-255 range.
exit(139): It indicates Segmentation Fault which means that the program was trying to access a memory location not allocated to it. This mostly occurs while using pointers or trying to access an out-of-bounds array index.
Exit Codes. Exit codes are a number between 0 and 255, which is returned by any Unix command when it returns control to its parent process. Other numbers can be used, but these are treated modulo 256, so exit -10 is equivalent to exit 246 , and exit 257 is equivalent to exit 1 .
Under Linux and most other Unix variants, the signal number 11 indicates a segmentation fault, as remarked by Kerrek SB.
Here is how cp
from coreutils-8.21
exits:
exit (ok ? EXIT_SUCCESS : EXIT_FAILURE);
There's nothing else than 0 or 1.
On Mac (10.12.5 (16F73)) there are additional codes. For instance:
Mac$ cp -W 1 2; echo $?
cp: illegal option -- W
usage: cp [-R [-H | -L | -P]] [-fi | -n] [-apvX] source_file target_file
cp [-R [-H | -L | -P]] [-fi | -n] [-apvX] source_file ... target_directory
64
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With