jl487
January 16, 2014, 8:46am
1
Hello, I have two bash scripts like the following:
script 1:
#!/bin/bash
var=WORLD
bash path/to/second/script/script2.bash
script 2:
#!/bin/bash
echo "HELLO $var"
I expected the output to be "HELLO WORLD" but instead, I get "HELLO". I understand that when I envoke another bash script, I'm starting a new processm but how can I go about changing it so that I can pass the variable to script 2?
Scott
January 16, 2014, 8:48am
2
Try exporting var.
export var=WORLD
Or, to satisfy your requirement ("How to pass variables...") in the strictest sense, follow Don's advice in the next post
jl487:
Hello, I have two bash scripts like the following:
script 1:
#!/bin/bash
var=WORLD
bash path/to/second/script/script2.bash
script 2:
#!/bin/bash
echo "HELLO $var"
I expected the output to be "HELLO WORLD" but instead, I get "HELLO". I understand that when I envoke another bash script, I'm starting a new processm but how can I go about changing it so that I can pass the variable to script 2?
Change your scripts to:
script 1:
#!/bin/bash
var=WORLD
bash path/to/second/script/script2.bash "$var"
script 2:
#!/bin/bash
echo "HELLO $1"