views:

465

answers:

2

Are the following 2 lines completely equivalent? If not what's the difference? I've seen plently of shellscripts utilize number 1 and was just wondering what it gives you compared with number 2.

  1. typeset TARGET="${XMS_HOME}/common/jxb/config/${RUNGROUP}.${ENV}.properties"
  2. TARGET="${XMS_HOME}/common/jxb/config/${RUNGROUP}.${ENV}.properties"
+1  A: 

typeset will create a local variable (one which doesn't "leak"). This is useful in functions but I've also seen it being used at the top level of a shell script.

a=0
x() {
    typeset a=1
}
x
echo $a
y() {
    a=2
}
y
echo $a

will print

0
2

You can also use typeset to create arrays and integers.

Aaron Digulla
A: 

since shell scripting is a loosely typed language (in which variables wont have a datytype) we can use typeset to set a particular variable to take similar datatype of values only.

Venkataramesh Kommoju