The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
typeset-r venkatakotiy UNIX and Linux Applications 1 05-21-2008 01:55 PM
Typeset bisla.yogender Shell Programming and Scripting 3 04-30-2008 06:45 AM
typeset balaji_prk Shell Programming and Scripting 1 06-27-2007 08:08 AM
typeset -f ??? xinfinity Shell Programming and Scripting 1 04-04-2006 04:43 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-18-2006
nervous nervous is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 55
typeset in Ksh

Hi,

Most of times, I see use of typeset command in ksh scripts, but I don't know what it exactly does. I would be thankful if any body could provide me a brief explanation of typeset in ksh and all of its options, like typeset -A, typeset -r, typeset -Z, typetset -L etc.
  #2 (permalink)  
Old 10-18-2006
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
Did you try the man pages for ksh ?
  #3 (permalink)  
Old 10-18-2006
tayyabq8's Avatar
tayyabq8 tayyabq8 is offline Forum Advisor  
Moderator
  
 

Join Date: Nov 2004
Location: Bahrain
Posts: 578
Quote:
Originally Posted by nervous
Hi,

Most of times, I see use of typeset command in ksh scripts, but I don't know what it exactly does. I would be thankful if any body could provide me a brief explanation of typeset in ksh and all of its options, like typeset -A, typeset -r, typeset -Z, typetset -L etc.
(Taken from HP-docs)

This command creates a shell variable, assigns it a value, and specifies certain attributes for the variable, such as integer and read-only.

The syntax is:
Code:
set typeset [-HLRZfilprtux [n] [name [=value]]...]
Where name is the shell variable to be created, value is to be assigned according to the options set.

The following example makes year read-only
Code:
$ typeset -r year=2000
$ echo $year
$ year=2001
ksh: year: is readonly
The following list of attributes may be specified by the designated option or flag:
Code:
-F   This flag provides UNIX to host name file mapping on non-UNIX machines.
 
-L   Left justify and remove leading blanks from value. If n is nonzero it defines the width of the field,
     otherwise it is determined by the width of the value of first assignment. When the parameter receives
     a value, it is filled on the right with blanks or truncated to fit into the field. Leading zeros are removed if 
     the -Z flag is also set. This turns the -R flag off.
 
-R   Right justify and fill with leading blanks. If n is nonzero it defines the width of the field, otherwise
     it is determined by the width of the value of first assignment. The field is left filled with blanks or truncated
     from the end if the parameter is reassigned. This turns the L flag off.
 
-Z   Right justify and fill with leading zeros if the first nonblank character is a digit and the -L flag has not been
     set. If n is nonzero it defines the width of the field, otherwise it is determined by the width of
     the value of first assignment.
 
-e   Tag the parameter as having an error. This tag is currently unused by the shell and can be set 
     or cleared by the user.
 
-f   The names refer to function names rather than parameter names. No assignments can be made
     and the only other valid flag is -x.
 
-i   The name is an integer. This makes arithmetic faster. If n is nonzero it defines the output arithmetic
     base, otherwise the first assignment determines the output base.
 
-l   All uppercase characters converted to lowercase. The uppercase flag, -u is turned off.
 
-p   The output of this command, if any, is written onto the two-way pipe.
 
-r   The given names are marked read-only and these names cannot be changed by subsequent
     assignment.
 
-t   Tags the name. Tags are user definable and have no special meaning to the shell.
 
-u   All lowercase characters are converted to uppercase characters. This turns the
     lowercase flag, -l, off.
 
-x   The given names are marked for automatic export to the environment of subsequently
     executed commands.
Using + rather than - causes these flags to be turned off. If no name arguments are given but flags are specified, a list of names (and optionally the values) of the parameters which have these flags set is printed. (Using + rather than - keeps the values to be printed.) If no names and options are given, the names and attributes of all parameters are printed.

The following example covers some of the attributes set above:
Code:
$ typeset -i arg1=3 arg2=22
$ echo $arg1 $arg2
3 22
$ typeset
...
export PATH
readonly year
integer arg2
integer arg1
...
$ typeset -u up=letters
$ echo $up
LETTERS
  #4 (permalink)  
Old 10-18-2006
Glenn Arndt's Avatar
Glenn Arndt Glenn Arndt is offline Forum Advisor  
Anomalous Lurker
  
 

Join Date: Feb 2006
Location: Indianapolis, IN
Posts: 255
As a corollary to this, could anyone please explain the -t option? I've always wondered about what that really did, but all I've ever found was the description in the man page.
  #5 (permalink)  
Old 10-19-2006
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
Quote:
Originally Posted by Glenn Arndt
As a corollary to this, could anyone please explain the -t option? I've always wondered about what that really did, but all I've ever found was the description in the man page.

It doesn't really do anything.


typeset -i abc # sets the variable to be integer type
typeset -t def # sets the variable to be tagged type

Setting the integer type affects the way the variable works. The tagged type has no effect. But as with any variable type, it responds to naked typeset commands.

typeset +i # list all integer variables
typeset +t # list all tagged variables

And you could do "typeset -i" or "typeset -t" to list the variables with their values. That's about all there is to it. Everyone expects more but there is no more.
  #6 (permalink)  
Old 10-19-2006
Glenn Arndt's Avatar
Glenn Arndt Glenn Arndt is offline Forum Advisor  
Anomalous Lurker
  
 

Join Date: Feb 2006
Location: Indianapolis, IN
Posts: 255
Thanks for the info. It seems strange -- I guess I could use it to track a list of variables for some user-defined purpose, but considering there are zillions of other ways to do something like that... ok. Thanks again, though.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:18 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0