LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-27-2011, 09:28 AM   #1
SilversleevesX
Member
 
Registered: May 2009
Posts: 181
Blog Entries: 9

Rep: Reputation: 15
BASH: Share one variable value between users -- possible?


(Particularly user A -- me -- and root.)

I know it can be done between login shells and subshells, or subshells to the primary running shell, as in a script, with the export command. But is there something similar in BASH (or any part of Linux) for passing a value set to a variable to the same, or a similar, variable that can be "echo-ed" and otherwise used by root, just to give an example?

BZT
 
Old 09-27-2011, 09:47 AM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
Not dynamically.

However what you could do is save the variable from the first session to a file:

Code:
echo $A >var.out
Then in your other session you can set the variable:

Code:
export A=$(cat var.out)
 
1 members found this post helpful.
Old 09-28-2011, 12:53 AM   #3
bsat
Member
 
Registered: Feb 2009
Posts: 347

Rep: Reputation: 72
I am not sure if this will help but may be you can put an export statement in rc.local .
 
Old 09-28-2011, 08:24 AM   #4
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
Quote:
Originally Posted by bsat View Post
I am not sure if this will help but may be you can put an export statement in rc.local .
I think the OP was asking if he was already logged in and running a session and set a variable could he then make another already logged in session use that same variable. The answer is no but he can do what I wrote above.

For having all sessions by a single user use the same variable at login he can put them in the user's .bashrc or .bash_profile rather than mucking with rc.local. For all sessions by all bash users he can put it in /etc/bashrc instead.
 
1 members found this post helpful.
Old 09-28-2011, 08:32 AM   #5
snooly
Member
 
Registered: Sep 2011
Posts: 124

Rep: Reputation: Disabled
sockets!
 
0 members found this post helpful.
Old 09-28-2011, 08:59 AM   #6
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
Quote:
Originally Posted by snooly View Post
sockets!
That seems like it would be a bit involved and not really relevant to bash directly. Maybe you have an idea you'd like to expand upon as simply writing "sockets!" to me is about helpful as writing "semaphaores!"?
 
Old 09-28-2011, 09:14 AM   #7
alienDog
Member
 
Registered: Apr 2004
Location: Europe
Distribution: Debian, Slackware
Posts: 505

Rep: Reputation: 48
So basically you're asking if the users can set/modify each others environment variables? Ummm.... No, ofcourse not It would mean that you could mess up somebody's session completely by altering their variables, or even spy on them. For example by directing their shell history to a file that is readable by you.
 
1 members found this post helpful.
Old 09-30-2011, 06:37 AM   #8
SilversleevesX
Member
 
Registered: May 2009
Posts: 181

Original Poster
Blog Entries: 9

Rep: Reputation: 15
Post

Quote:
Originally Posted by alienDog View Post
So basically you're asking if the users can set/modify each others environment variables? Ummm.... No, ofcourse not It would mean that you could mess up somebody's session completely by altering their variables, or even spy on them. For example by directing their shell history to a file that is readable by you.
I was thinking of that OL. I thought there might be a security consideration involved (inherent?) in why it couldn't be done. I just couldn't come up with anything specific. Thanks for giving a little focus to it. BZT
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[bash] re-evaluate variable inside variable muzzol Programming 9 12-01-2010 11:31 AM
Bash: How do I read data from a variable while that variable is being populated? theaceoffire Programming 4 04-23-2010 02:29 PM
-bash: HISTSIZE: readonly variable -bash: HISTFILESIZE: readonly variable deathsfriend99 Linux - Newbie 4 12-08-2009 12:51 PM
How to get variable from text file into Bash variable mcdef Linux - Software 2 06-10-2009 01:15 PM
Problem with bash script - variable name within variable name steven.c.banks Linux - Newbie 3 03-10-2009 03:08 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:58 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