0

I'm not sure the title is very explicit, sorry for that, but I couldn't find a clearer way to describe my problem in so few words.

So I'll explain my problem here (and if an admin/someone finds a more suitable title, please change it/tell me so that I'll change it).

Let's say I have the following bash script, let's call it main.sh:

#!/bin/bash
var1="foo"
var2="bar"
var3="baz"
var4="qux"

# Some command here

and another script, external.sh, which simply looks like

echo $var1 $var2 $var3 $var4

Is there a way I can simply paste the external.sh under the "# Some command here" line in main.sh, so that when I execute main.sh, it echoes "foo bar baz qux" as expected?

I've already tried to add a line like cat external.sh but of course the output of ./main.sh is 'echo $var1 $var2 $var3 $var4'.

I know there are some alternatives, like transforming external.sh into a real bash script with 4 arguments, and execute external.sh from main.sh with $var1..$var4 as arguments, but that is not really what I want here.

So any help would be much appreciated.

1 Answer 1

2
source external.sh

or, shorter

. external.sh

See http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/x237.html

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.