"Taking a LiveFire Labs' course is an excellent way to learn
Linux/Unix. The lessons are well thought out, the material is
explained thoroughly, and you get to perform exercises on a real
Linux/Unix box. It was money well spent."
Ray S.
Pembrook Pines, Florida
LiveFire Labs' UNIX and Linux Operating System Fundamentals
course was very enjoyable. Although I regularly used UNIX systems
for 16 years, I haven't done so since 2000. This course was a
great refresher. The exercises were fun and helped me gain a real
feel for working with UNIX/Linux OS. Thanks very much!"
Ming Sabourin
Senior Technical Writer
Nuance Communications, Inc.
Montréal, Canada
Read more student testimonials...
Receive UNIX Tips, Tricks, and Shell Scripts by Email
LiveFire Labs' UNIX Tip,
Trick, or Shell Script of the Week
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
$
Read the NEXT article in this series -
Managing Variable
Attributes with typeset - Part II