LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 02-21-2006, 03:28 AM   #1
kloss
Member
 
Registered: Nov 2004
Location: France & Germany
Distribution: (Pure) Debian Etch & Sid
Posts: 116

Rep: Reputation: 15
How can I define a global variable?


Hi all,
I want to define a global variable. If I do:
Code:
foo="bar"
the variable is only defined for the current term, not for the terms I'm going to open.

If I do:
Code:
export foo="bar"
it is not better, because my variable is not a classical environment variable like PATH or TERM, but a "personal" one.

I don't want to set the variable in a configuration file like .bashrc, because the variable changes from time to time (it is not the same during the whole session).

Which command do I have to use?

Thanks in advance ++
Kloss
 
Old 02-21-2006, 03:47 AM   #2
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
No shell variable will cross different terminals.
Use a file to store the content, and have the variable being updated on the other terminals by reading again that file.
 
Old 02-21-2006, 03:54 AM   #3
kloss
Member
 
Registered: Nov 2004
Location: France & Germany
Distribution: (Pure) Debian Etch & Sid
Posts: 116

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by jlliagre
No shell variable will cross different terminals.
Use a file to store the content, and have the variable being updated on the other terminals by reading again that file.
Yeah, that would be an easy way... but it is somewhat "dirty". It's a bit curious that there is no clean way to do that with linux.

Anyway, thanks for your quick answer
 
Old 02-21-2006, 04:07 AM   #4
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
I don't feel it is dirty.

Should you really need that feature, a way to implement it would be to patch the shell source code to have a shared memory pool accessible by every shell instance, and have some variables content stored there. Not a quick job.
 
Old 02-21-2006, 04:30 AM   #5
kloss
Member
 
Registered: Nov 2004
Location: France & Germany
Distribution: (Pure) Debian Etch & Sid
Posts: 116

Original Poster
Rep: Reputation: 15
Quote:
Should you really need that feature, a way to implement it would be to patch the shell source code to have a shared memory pool accessible by every shell instance, and have some variables content stored there. Not a quick job.
Good idea! I'm gonna learn C, get to know the shell source code and register the http://regedit.sourceforge.net web page

Actually it was just to get a small script running, and the file trick works, so I will keep this easy solution ^^

Bye ++

Last edited by kloss; 02-21-2006 at 04:37 AM.
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Python Global Variable? ElementNine Programming 5 11-05-2007 12:53 PM
diff between #define and const defined variable b123coder Programming 7 06-27-2005 08:02 AM
problems with a global variable javier_ccs Programming 2 06-21-2005 12:18 PM
how am i define an environment variable? yenonn Slackware 2 12-19-2003 07:44 AM
how to define a global variable Anniebaby Programming 1 11-09-2003 10:43 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 03:34 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration