Name
set
Synopsis
set [-r]variable
=value
set [-r]variable
[n
] =value
set [-f | -l]variable
=(list
) set [-r]variable
set [-r]
Set variable to
value or, if multiple values are specified,
set the variable to the list of words in the value list. If an
index n is specified, set the
n th word in the variable to
value. (The variable must already contain at
least that number of words.) If only variable
is specified, set the variable to null. With no arguments, display
the names and values of all set variables. See also the section
“Predefined Shell Variables,” earlier in this chapter. Only one of
-f
or -l
can be given.
Options
-
-f
When setting a variable to a list, remove duplicate words from the list, keeping only the first occurrence of a duplicate.
-
-l
When setting a variable to a list, remove duplicate words from the list, keeping only the last occurrence of a duplicate.
-
-r
List only read-only variables, or set specified variable to read-only.
Examples
%set list=(yes no maybe)
Assign a wordlist %set list
[3
]=maybe
Assign an item in existing wordlist %set quote="Make my day"
Assign a variable %set x=5 y=10 history=100
Assign several variables %set blank
Assign a null value to blank
Get Unix in a Nutshell, 4th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.