Accessing local variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Accessing local variable
# 1  
Old 06-09-2011
Accessing local variable

Hi,

Would like to know the purpose and accessing of local variable as in below code snippet:

HTML Code:
a=123
( a=321; )	      

echo "a = $a"   #This will print 123
How to access local a variable which is assigned with value 321 ?. ..



# 2  
Old 06-09-2011
The short answer: Like this, you can't.

From the BASH man-page:
Code:
(list) list  is executed in a subshell environment

Code:
a=123
( a=321;
  echo "a = $a"   #This will print 321
)

# 3  
Old 06-09-2011
Okay. ..

Any purpose behind it?. .. Or it is like a dummy value assigned to some orbitery variable?.

Thank you.
# 4  
Old 06-09-2011
purpose willbe, If you want to do some calculation on same variable which is used by parent shell and don't want to replace the value of parent shell variable.
This User Gave Thanks to vidyadhar85 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Significance of ':-' while accessing a variable

Hi I was trying to understand what ':-' means when used with variables echo ${x:-10} if Thanks (4 Replies)
Discussion started by: zulfi123786
4 Replies

2. Shell Programming and Scripting

accessing variable from while loop

Hi all, Here is an outline of the problem: #variable declared at start of script x=0; #a function that increments x by 1 every 10 seconds incrementX(){ increments x every 10 seconds; } #i want this to output the value of x every second. The problem is that x is always reported... (3 Replies)
Discussion started by: free2rhyme2k
3 Replies

3. Shell Programming and Scripting

Help with awk and accessing variable values within the syntax

I'm writing a bash script, and I am having trouble with this line: awk '{print "url = \"http://www.example.com/directory/$type/"$1"\""}' input.file > output.file Within the URL being printed, I wish the value of the variable "$type" to be printed, after being read from user input from the... (2 Replies)
Discussion started by: meridionaljet
2 Replies

4. Shell Programming and Scripting

Accessing a variable from another file

HI all, How can i access a variable that is defined in another file as: $$Name= "abhinav; in my script. The catch is that it has 2 $s behind it... Thnaks ---------- Post updated at 10:36 AM ---------- Previous update was at 10:29 AM ---------- the file from which i have to... (0 Replies)
Discussion started by: abhinav192
0 Replies

5. Shell Programming and Scripting

accessing a variable or array of one script in another

hi all, i've a requirement like this. i want to access the contents of an array declared in one script,which is a bash script, to a second script which is a perl script. actually i want a sort of global variable which can be accessed in other script like environmen variables and also i can... (3 Replies)
Discussion started by: tprayush
3 Replies

6. Shell Programming and Scripting

Accessing the variable from pl sql bolck

I hve a PL SQL block in unix where i define a variable "var_px_cat" and use it for taking count SELECT COUNT(*) INTO var_px_cat FROM A WHERE B = '$CATEGORIE_ID'; Now how do I access the variable "var_px_cat" in unix after exiting from pl sql block. (3 Replies)
Discussion started by: theeights
3 Replies

7. Shell Programming and Scripting

Accessing a variable from another script

Hi, Can anyone assist me on how to access a variable in a shell script from another script. for ex, Script-1 ------- #! /bin/sh c=10 Where as, i would like to access the velue of variable c in another script 'Script-2'. Thankyou to all in advance !! :b: :b: (2 Replies)
Discussion started by: little_wonder
2 Replies

8. UNIX for Dummies Questions & Answers

Accessing Global Env Variable

Greetings: I need to remove 'RUBYOPT' env variable to install MacRuby. I see it via $env (tchrc). I checked my (local) .tcshrc, .login, .profile files: not defined there. Apparently, it's not set locally. I know this RUBYOPT is global, since I can see it in another account on my... (4 Replies)
Discussion started by: UncleRic
4 Replies

9. Shell Programming and Scripting

Accessing invidual characters in a variable name

hi, How do i access individual characters in a string variable value . say i have var=20060731. How do i retrieve 2,0,0,6 etc chars separately. Is there any Field separator in cut or awk to achieve the same? Regards, Suman (2 Replies)
Discussion started by: suman_jakkula
2 Replies

10. UNIX for Dummies Questions & Answers

Accessing remote machine via an enviroment variable

Hi. Is it possible to remotely access another unix box via an enviroment variable, on another machine? I am trying to create an environment variable $MIPSDATA which will point to a folder on another machine. I have setup the .rhosts file and got that working on both machines (tested via a... (4 Replies)
Discussion started by: ElCaito
4 Replies
Login or Register to Ask a Question