LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 07-20-2010, 03:42 AM   #1
paliga
Member
 
Registered: Feb 2010
Posts: 39

Rep: Reputation: 0
protect environment variable


Hi,

Im wondering if there is a simple way to protect environment variables to be changed by child processes?

Thank you in advance,

k.

EDIT: its the default... isn't it?

Last edited by paliga; 07-20-2010 at 04:13 AM.
 
Old 07-20-2010, 07:10 AM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
It's not the "default", per-se. It's simply that a child process can never affect the environment of its parent, no matter what you do. But any variable that's been given the "export" value will be inherited by any sub-shells launched, and the subshell version of the variable can be changed. When the sub-process is closed, its environment, including any changes, is lost, while the environment of the parent shell is still there unaltered.

In simple terms, changes can propagate down, but never up.

By the way, any variable can be set to read only (in bash) with "declare -r variablename", although again the setting will only affect the current shell level and its sub-processes. Be careful with the read-only value though, particularly with environmental variables, because once set, it can never be unset for as long as that process exists.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Environment Variable linux_linux Linux - Newbie 4 03-20-2008 10:16 PM
Environment variable.. manomohan Programming 1 02-26-2007 11:27 PM
LXer: Oin Gets More Patents to Protect Linux Environment LXer Syndicated Linux News 0 05-24-2006 04:54 PM
Environment Variable salmanucit Linux - Software 2 07-21-2004 02:27 AM
environment variable mimi Linux - General 2 04-10-2002 07:45 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:16 AM.

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