0

I have many BASH scripts called in sequence, e.g., script1.sh contains:

#!/bin/bash

bash script2.sh
bash script3.sh
bash script4.sh

script2.sh contains:

#!/bin/bash

file_a="1.txt"

cp $file_a /tmp/$file_a.tmp

script3.sh contains:

#!/bin/bash

wc -l /tmp/$file_a.tmp

script4.sh contains:

#!/bin/bash

cat /tmp/2.txt $file_a.tmp > file3.txt

Each file requires access to a small collection of variables. How can I pass the variables from one script onto the next?

Village
  • 22,513
  • 46
  • 122
  • 163

1 Answers1

0

You have many options.

The first method would be making the variable as the environment variable and pass to the script before the second script get executed.

The second method would be making the second script to run in the same shell.

The methods are described well here with the examples.

halfer
  • 19,824
  • 17
  • 99
  • 186
Avinash Babu
  • 6,171
  • 3
  • 21
  • 26