Set status codes for builtins
Closed this issue · 0 comments
derfleck commented
All builtins should set the status code g_stat
according to its execution. They should return the value after execution as an int, because the error codes need to be handled in both parent and child processes. All should return 0 on success and an error code on failure. The builtins seem to have different behaviour:
- env: returns 127 when used with an argument, prints an error message
- cd: returns 1 when trying to use it with an invalid path/filename or with too many arguments
- export: returns 1 when using an invalid key
- unset: couldn't trigger an error, always returned 0, even though it should return (according to manual) a value bigger than 0 if any value couldn't be unset
***unset returns 1 only when error code is printed (not a valid identifyer) - echo: couldn't trigger an error, always returned 0
- exit: sets the error code to 0 if no argument provided, 1 if too many arguments, 2 if argument is non-numeric, otherwise argument value (but should overflow, only unsigned char values from 0 to 255 allowed, therefore 258 would overflow to 2 and be set accordingly)