LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 07-23-2005, 01:33 AM   #1
alaios
Senior Member
 
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,133

Rep: Reputation: 45
bash programming


Hi ...
I want to create ascript that can read and modify a environmental variable... Cn u help me a little?
For example
a=2
sh myscript
a has value 2
changing a
a has value 3

After the script has stopeed executing i want to read the new value of a .... Any good suggestion? Thx a lot
 
Old 07-23-2005, 01:52 AM   #2
Matir
Moderator
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 118Reputation: 118
You cannot do this in the way you have described. A script can only change variables in its own environment, which are then inherited by children, but leave parents unaffected. The closest you can get is this:
Code:
#!/bin/bash
export a=NEW_VALUE
Code:
$ source SCRIPT_ABOVE.sh
You can also use a single '.' (dot) as a shortcut for source, like so:
Code:
$ . SCRIPT_ABOVE.sh
 
Old 07-23-2005, 01:52 AM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,004
Blog Entries: 11

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
Quote:
want to create ascript that can read and modify a environmental variable... Cn u help me a little?
For example
What have you tried so far?


Cheers,
Tink
 
  


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 programming winterhunter Linux - Newbie 6 11-26-2007 08:14 AM
Bash Programming moodupani Programming 1 08-31-2005 07:50 PM
bash programming drisay Programming 6 12-20-2004 10:09 AM
bash programming cpukiller Linux - Newbie 1 11-04-2003 07:45 PM
bash programming bulliver Programming 2 04-05-2003 10:30 PM


All times are GMT -5. The time now is 10:33 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration