LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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, 12:33 AM   #1
alaios
Senior Member
 
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,203

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, 12:52 AM   #2
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
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, 12:52 AM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
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



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

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

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