LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-09-2008, 02:45 PM   #1
Frederick J. Harris
LQ Newbie
 
Registered: May 2007
Posts: 10

Rep: Reputation: 0
Set/Get Linux Environment Variables


How does one view or change/set environment variables in Linux? In DOS one uses the SET command. I am using Ubuntu 6.1 Edgy Eft.

The context for my question is that for some time now I have been attempting to teach myself Xlib/Xt/Motf programming as a Linux newbie. I’m just getting into the Motif part now using Lesstif, which so far, has been compiling and working good for me at this very basic level. I finally hit chapter three of Douglas A. Young’s book “The X Window System Programming And Applications With Xt”, 1994, and I’m foundering rather badly on this chapter about resources. The first two chapters went fine, and the rest of the book looks really good, but chapter three is killing me! I’ve never run into material like this before. I’m a Windows Api programmer, and in the Windows environment these things that appear to be called ‘Resources’ in Unix/Linux are termed system settings in Windows. Application programmers usually don’t need to deal with them (at least I never have).

From my study of the aforementioned book and also Adrian Nye’s ‘Xlib Programming Manual’, I have come to understand that Xlib/Xt/Motif programs obtain Resource information from about a half dozen or more sources, and depending on rather complicated ‘precedence rules’, places this information into some sort of Resource Database ultimately located God only knows where! Intimately involved in all these machinations are a number of environment variables such as XENVIRONMENT, XFILESEARCHPATH, XUSERFILESEARCHPATH, etc. Depending on whether or not these variables are defined or not resource values can or may be read out of such files as an .Xdefaults file that itself can assume various forms and locations. This stuff is so obscure I’m wondering if I may saftly bypass it and get on to using the various widgets and their algorithims, which I find considerably more interesting and productive. But being the newbie I am I’m not sure what’s important and what isn’t.

Also, how can one determine if the root window has a RESOURCE_MANAGER property?

Thanks

Fred
 
Old 02-09-2008, 03:26 PM   #2
cmnorton
Member
 
Registered: Feb 2005
Distribution: Ubuntu, CentOS
Posts: 585

Rep: Reputation: 35
one example

# For use within a shell script. Can be lowercase. There can be no spaces
# between the env variable and the value.

MAIL_DELIVERY_COMPLETE=0
...

if [ $MAIL_DELIVERY_COMPLETE -eq 1 ]; then
...
else
...
fi

If you want this environment variable to be known outside the shell script -- the shell script runs another script that is looking for this environment variable, put an export in front of the environment variable.

export MAIL_DELIVERY_COMPLETE=0

There are some rules I've seen about upper and lower case relating to whether you are working with local or global environment variables. I have not paid much attention to these.

You should probably also read man let, because that's another way to set bash variables.

Please note export in front of a variable won't work in OSs like SCO. You'd have to MAIL_DELIVERY_COMPLETE=0; export MAIL_DELIVERY_COMPLETE.

Even if you export this variable in the shell script, it will only be available during the duration of the shell script's life. If you want the environment variable to stick around, put a "." in front of the shell script when you run it.

Last edited by cmnorton; 02-09-2008 at 03:27 PM. Reason: shorten
 
Old 02-09-2008, 04:12 PM   #3
Uncle_Theodore
Member
 
Registered: Dec 2007
Location: Charleston WV, USA
Distribution: Slackware 12.2, Arch Linux Amd64
Posts: 896

Rep: Reputation: 71
Well, you might wanna look here
http://en.wikipedia.org/wiki/X_resources
(also, some links at the top of that page)
and maybe here
http://www.cptec.inpe.br/sx4/sx4man2/g1ae02e/appd.html

Also, I would get a newer book. A lot of things have changed since 1994...
 
Old 02-10-2008, 01:02 PM   #4
Frederick J. Harris
LQ Newbie
 
Registered: May 2007
Posts: 10

Original Poster
Rep: Reputation: 0
Thanks for the input cmnorton and uncle theodore. I've decided to put the whole thing aside and come back to it later if need be. It became clear to me it was a can of worms I could avoid for now. I'm making good progress in my endeavors now.

Honestly uncle theodore, it appears hard to find actual books on either XLib or Motif. I believe the two I have are about it. I saw that Jesse Liberty had a fairly new book on X programming, and the reviews of it were terrible. My XLib reference has a copywrite of 1992 on it! It still uses the old original C syntax! However, the programs work OK otherwise. I had never seen that odd syntax, but I figgured it out.

The previously mentioned Xt book is also very good, except for that strange chapter I got stuck on.

I'm assumming people use other tools nowdays to write Linux programs, and indeed, I also have a brand new and justpublished GTK+ book, but I wanted to start with the older stuff - get caught up with the history so to speak.

Fred
 
  


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
set environment variables johnvdster Linux - Newbie 2 05-30-2006 06:15 AM
SLES: Why don't my environment variables get set? eantoranz Linux - Software 4 11-01-2005 12:49 PM
how do i set environment variables? guitarfella Slackware 2 12-05-2004 12:05 AM
How to set environment variables anjaan Linux - General 3 06-10-2004 03:04 PM
Help with the currently set environment variables!! apoc013 Linux - Newbie 6 01-21-2004 02:28 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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