December
15, 2003 -
Managing Variable Attributes with typeset
- Part I
|
|
As
your shell scripts become more diverse and
complex, there will be times when you will
want or need to manipulate the attributes
of a script's variables. The typeset
command allows you to set, unset, and
display these attributes. The syntax
for typeset is:
|
typeset -option(s)
[variable_name[=value]]...
|
|
A
minus sign before the option list sets the
attributes for the variable list.
Variable attributes can be unset by
replacing the minus sign with a plus sign:
|
typeset +option(s)
[variable_name[=value]]...
|
Notice
that the variable name and value are
optional arguments. If these are not
included after specifying one or more
attributes, the variables having the
specified attribute(s) and their values will
be displayed when the minus sign is used:
|
$ typeset -l
animal1=dog
animal2=cat
animal3=duck
$
|
When
a plus sign is used, only the variable names
are displayed:
|
$ typeset +l
animal1
animal2
animal3
$
|
The option
"l" is used to set, unset, and
display (as seen above) the lowercase
attribute:
|
$ typeset -l answer
$ answer=Y
$ print $answer
y
$
|
In this example,
the lowercase attribute is first set for the
variable answer. No initial value is
assigned to answer. The second
statement assigns the uppercase letter
"Y" to answer, and as you can see,
the value is automatically converted to
lowercase. To set the uppercase
attribute for a variable, the -u option is
used:
|
$ print $answer
y
$ typeset -u answer
$ print $answer
Y
$
|
|
|
|
|
|
|
|
|
|
|
Learn
more...
If you are new to the UNIX or Linux
operating system and would like to learn
more, you may want to consider
registering for LiveFire Labs' UNIX
and Linux Operating System Fundamentals
online training course.
If you already have a solid grasp of the
fundamentals but would like to learn more
about the Korn shell and basic and
advanced shell scripting, taking our Korn
Shell Scripting course will be
beneficial to you.
Our
innovative hands-on training model allows
you to learn
UNIX by completing hands-on
exercises on real servers in our Internet
Lab.
More
Tips...
· Popular
UNIX Tips from the Past
|
|