set, unset - Set or unset shell variables


set [ name=value… ]
unset name


With no arguments, set lists all shell variables and their values. With arguments, set assigns a value to the variable name given.


set hello=world

Sets the variable hello to the value “world”. To access the value in this new variable, prefix it with a dollar sign, as in:

1% echo $hello world 2% ls $hello world: directory not found

Multiple variables can be assigned all at once, as with:

set foo=bar seven=7 hard="disk drive"

To erase a variable, the unset command is used with one or more variable names:

3% unset hello 4% unset crash bang bigbang bam

Note that variables used in the value portion of a set command are expanded into the value. This may not be desirable. In the case where the variable should not be expanded during the assignment, escape the variable with a backslash (\):

set prompt="[\$cwd] "

See Also