Home About BC DR HA Support Training Download
You are here: Home/ Downloads/ Scripts/ Korn/ Please Login or Register

-
Current Location
-

js
  Downloads
    Scripts
      Korn



-
 Mt Xia Inc.
-
BOOK:Advanced Shell Scripting



 Join our LinkedIn Group
AIX Advanced Technical Experts
Contract Opportunities

www.LinkedIn.com
-
 Train By Tweet
Training courses Tweet By Tweet
Various Subjects and Products
TrainByTweet.com


AIX Admin Methodology
Global Consolidation Project
All AIX admins should join
www.aixexpert.com
-

digg Digg this page
del.icio.us Post to del.icio.us
Slashdot Slashdot it!


AIX FREE DEMO UNIX
Automated AIX Deployment
Reduce your DC costs

www.siteox.com

LPAR Leasing
Lease an AIX / i5 LPAR
Reduce your costs

www.mtxia.com

Server Leasing
Lease a Server off-site
Reduce your costs

www.mtxia.com

Data Center Automation
Business Continuity and DR
Virtualization/Consolidation

www.mtxia.com

HMC Service
Hardware Management Console
Manage Remote AIX / i5 LPARs

www.siteox.com

Business Web Site Hosting
$3.99 / month includes Tools,
Shopping Cart, Site Builder

www.siteox.com

Disaster Recovery
Small Business Oriented
Off-Site Facilities

www.mtxia.com

IBM pSeries / iSeries
Reduce your Costs
Off-Site Server Hosting

www.mtxia.com

The following script provides several examples of using "discipline" funtions within Korn Shell 93.


#!/usr/bin/ksh93
################################################################
# A discipline function is a function that is associated with a specific
# variable. This allows you to define and call a function every time that
# variable is referenced, set, or unset. These functions take the form of
# varname.function, where varname is the name of the variable and function
# is the discipline function. The predefined discipline functions are get,
# set, and unset.
# 
#     * The varname.get function is invoked every time varname is
#     referenced. If the special variable .sh.value is set within this
#     function, then the value of varname is changed to this value. 
#     A simple example is the time of day:
# 
# $ function time.get 
# > { 
# >     .sh.value=$(date +%r) 
# > } 
# $ print $time 
# 09:15:58 AM 
# $ print $time    # it will change in a few seconds 
# 09:16:04 AM
# 
#     * The varname.set function is invoked every time varname is set. The
#     .sh.value variable is given the value that was assigned. The value
#     assigned to varname is the value of .sh.value when the function
#     completes. For example:
# 
# $ function adder.set 
# > { 
# >   let .sh.value="
# $ {.sh.value} + 1" 
# > } 
# $ adder=0 
# $ echo $adder 
# 1 
# $ adder=$adder 
# $ echo $adder 
# 2  
# 
#     * The varname.unset function is executed every time varname is
#     unset. The variable is not actually unset unless it is unset 
#     within the function itself; otherwise it retains its value.
# 
# Within all discipline functions, the special variable .sh.name is set to
# the name of the variable, while .sh.subscript is set to the value of the
# variables subscript, if applicable.
# 
# Compound variables are supported. A compound variable allows a user to
# specify multiple values within a single variable name. The values are
# each assigned with a subscript variable, separated from the parent
# variable with a . (period). For example:
# 
# $ myvar=( x=1 y=2 ) 
# $ print "${myvar.x}" 
# 1
# 
################################################################
function DATETIME.get
{ 
  print "\ninside the DATETIME.get function"
    print ".sh.name=${.sh.name}"
    print ".sh.value=${.sh.value}"
    print ".sh.subscript=${.sh.subscript}"
    .sh.value=$( printf "%(%c)T\n" )
} 
################################################################
function DATETIME.set
{
  print "\ninside the DATETIME.set function"
    print ".sh.name=${.sh.name}"
    print ".sh.value=${.sh.value}"
    print ".sh.subscript=${.sh.subscript}"
}
################################################################
function DATETIME.unset
{
  print "\ninside the DATETIME.unset function"
    print ".sh.name=${.sh.name}"
    print ".sh.value=${.sh.value}"
    print ".sh.subscript=${.sh.subscript}"
}
################################################################

DATETIME="test"

print "${DATETIME}"

unset DATETIME

-
Example Discipline Functions
-
 


AIX FREE DEMO UNIX
Automated AIX Deployment
Reduce your DC costs

www.siteox.com

LPAR Leasing
Lease an AIX / i5 LPAR
Reduce your costs

www.mtxia.com

Server Leasing
Lease a Server off-site
Reduce your costs

www.mtxia.com

Data Center Automation
Business Continuity and DR
Virtualization/Consolidation

www.mtxia.com

HMC Service
Hardware Management Console
Manage Remote AIX / i5 LPARs

www.siteox.com

Business Web Site Hosting
$3.99 / month includes Tools,
Shopping Cart, Site Builder

www.siteox.com

Disaster Recovery
Small Business Oriented
Off-Site Facilities

www.mtxia.com

IBM pSeries / iSeries
Reduce your Costs
Off-Site Server Hosting

www.mtxia.com