View Full Version : Batch Variables

April 21st, 2010, 10:57 PM
Hello World!

This may sound a little bit weird because I'm an Ubuntu enthusiast currently using Windows XP, but I'm making a batch file that finds a drive, and then (this is where I'm stumped) in another batch file, I want to use that set variable.
My instincts are telling me just to use that same variable and try to not set it over in another file, but I think (like always) there's a chance that that's wrong.

Thanks for any assisstance.

April 22nd, 2010, 04:03 AM
The variable will carry over if you invoke the second script using "source", otherwise if you simply execute it it won't - you'd need to instead pass the variable value as an argument.



myvar="blah blah"
source ./b.sh



echo "myvar = $myvar"

(make both files executable)

> ./a.sh
myvar = blah blah

But when a.sh is:


myvar="blah blah"

we get:

> ./a.sh
myvar =

April 22nd, 2010, 04:08 AM

Batch, not bash.

April 22nd, 2010, 04:16 AM
Batch, not bash.

D'Oh!! :mad:

This gross misinterpretation on my part needs some Freudian analysis. Any interested parties, please proceed...