How to pass variables between scripts?

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?

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 :slight_smile:

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"