LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   bash programming (https://www.linuxquestions.org/questions/programming-9/bash-programming-345896/)

alaios 07-23-2005 12:33 AM

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

Matir 07-23-2005 12:52 AM

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

Tinkster 07-23-2005 12:52 AM

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


All times are GMT -5. The time now is 01:28 PM.