unset command (unsets variable values and attributes)
- Organization of this page
Format
unset [-f] name [ name ...]
Description
This command unsets specified variables or functions. You can specify more than one variable or function name. When you execute the command with the -f option specified, each name is assumed to be a function name, and the specified function definitions are removed.
Arguments
- -f
-
Specifies that this command applies to removal of function definitions.
- name
-
Specifies the name of a variable or function that is to be removed. You can also specify the name of an array.
If an array name is specified, all the elements that constitute the array are unset. To unset only one element, specify array-name[element-number] in name.
If the read-only attribute is set for a variable whose name is specified, the command terminates with an error. When you execute this command with an undefined variable name or function name specified in name, it terminates with an error.
Return codes
Return code |
Meaning |
---|---|
0 |
Normal termination |
1 |
Error termination (such as that a name specified in name is not defined as a variable or function) |
Notes
-
If you use this command to unset shell variables such as LINENO, OPTARG, OPTIND, RANDOM, and SECONDS, the special meanings of the shell variables will be lost, even if you define them again later.
-
If you use this command to unset array elements individually, they will still count as defined variables in the debugger, and you will still be able to use the debug command to display or set them.
However, if you unset all the elements that constitute an array, they will be treated as undefined variables in the debugger, and you will no longer be able to use the debug command to display or set them. For details about using the debug command to display and set variable values, see 6. Debugging Job Definition Scripts.
-
If the command syntax of this special built-in command is invalid, it exits the shell that is executing the command.
Usage examples
-
Remove a variable.
unset val
-
Remove a function.
unset -f func