Typeset issue


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Typeset issue
# 1  
Old 12-22-2015
Typeset issue

Code:
function fxn
{
  echo "target in build_ndm is $target"
}

function main
{
  target=${server_type}
  echo "target in main is $target"
  fxn
}

In the above the value of target is not being propagated to the function while ideally it should be since typeset variables are visible in sub functions

What is the issue here

Moderator's Comments:
Mod Comment edit by bakunin: Please use CODE-tags as prescribed by the forum rules. Thank you.

Last edited by Scrutinizer; 12-24-2015 at 06:16 AM.. Reason: Restored content deleted by OP, otherwise thread incomprehensible
# 2  
Old 12-22-2015
Quote:
Originally Posted by sharad.40216
In the above the value of target is not being propagated to the function while ideally it should be since typeset variables are visible in sub functions

What is the issue here
The issue is that "$target" is assigned some unspecified value "$server_type", which may contain either an empty value or might be undefined or maybe contains characters with a special meaning to the shell so that they become interpreted because the variable "$server_type" is used without proper quoting.

In addition, you seem to have no firm grasp of the variable scope in shell languages. The "typeset" keyword just declares a variable. You need to "export" them to make them available in subshells.

To top it off the concept of using a variable from the calling function is flawed in itself: if you want to pass some value to a subfunction use some explicit mechanism, like passing a parameter:

Code:
function sub1
{
target="$1"
print - "target in sub1() is: $target"
return 0
}


function caller
{
target="some-value"

print - "target in caller() is: $target"
sub1 "$target"

return 0
}

Finally, you have neither supplied complete code (because the snippet you presented seems to be only a small incomplete part) and you haven't shown any output the complete script has produced. How are we supposed to find out what went wrong with such incomplete data? We're admins, not psychics.

I hope this helps.

bakunin
# 3  
Old 12-23-2015
The original thread content ( as the original poster was rude enough to edit and remove...) :
Code:
function fxn
{
echo "target in build_ndm is $target"
}
function main
{
target=${server_type}
echo "target in main is $target"
fxn
}

In the above the value of target is not being propagated to the function while ideally it should be since typeset variables are visible in sub functions

What is the issue here

Last edited by vbe; 12-23-2015 at 10:43 AM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Typeset

I don't have man typeset entry in unix. what is the use of typeset command and can you give some examples for that. (1 Reply)
Discussion started by: ramkumar15
1 Replies

2. Linux

Issue with typeset in Linux

Hi All, typeset -Z4 curtime command is giving different result than expected inside scripts in linux.But it gives expected results outside the scripts.Can you please help us ---------- Post updated at 05:37 AM ---------- Previous update was at 05:25 AM ---------- curTime=`date +%H%M`... (5 Replies)
Discussion started by: sumqwe
5 Replies

3. Shell Programming and Scripting

Typeset command issue

Hi, As per my understanding typeset wil lmake a variable constant or readonly and -i option will make a variable integer. But please see the below outputs typeset -i abc=000001;echo $abc 1 typeset -i abc=0000010;echo $abc 8 typeset -i abc=00000100;echo $abc 64 typeset -i... (3 Replies)
Discussion started by: ratheeshjulk
3 Replies

4. Shell Programming and Scripting

Why use typeset?

Hi, All the scripts we have here use typeset instead of normal variables. They don't have any parameters, they just get declared at the beginning of the scripts like this: typeset var1 var2 var3Could anyone tell me why this is done? I don't see the advantage in this over using normal variables. (1 Reply)
Discussion started by: Subbeh
1 Replies

5. UNIX for Dummies Questions & Answers

Typeset

Hi, Can any one please explain me the use of 'typeset' in shell scripting? I donot under stand the use and advantages of using typeset. In one of our script, it is written like typeset VERBOSE NO_UPDATE typeset LOAD_SYBASE_TABLES I donot understand what actually these lines do. As per my... (2 Replies)
Discussion started by: siba.s.nayak
2 Replies

6. UNIX and Linux Applications

typeset-r

Hi All , Can any one help me the meaning of typeset -r Thanks, venkat (1 Reply)
Discussion started by: venkatakotiy
1 Replies

7. Shell Programming and Scripting

Typeset

Hi, Could any one please explain about typeset or share any link from where i can study about typeset i.e how to use it, how to define it.. etc? Thanks- Yogi (3 Replies)
Discussion started by: bisla.yogender
3 Replies

8. Shell Programming and Scripting

typeset

Can anyone show me a simple practical usage of typeset. (1 Reply)
Discussion started by: balaji_prk
1 Replies

9. Shell Programming and Scripting

typeset -f ???

I have found this command *typeset* and the option * -f *, which should provide me the list of all the currently defined functions. Is there any possibility of specifying the file in which this command to search ? (1 Reply)
Discussion started by: xinfinity
1 Replies

10. UNIX for Dummies Questions & Answers

TYPESET use

Hi all, I have problem understanding shell script.Written that $bindir/put_load.ksh ; typeset RV= $? I dont have any other document about script. How can i find that $bindir is exist or not what is the content of that, i am working on new box . how can i search that in old box what... (4 Replies)
Discussion started by: sam71
4 Replies
Login or Register to Ask a Question