1

I have two bash scripts: main one and auxiliary.

Let's say main script is:

#!/bin/bash

echo "This is start of my main script"
./auxiliary.sh
echo "This is end of my main script"

and auxiliary one is:

cd some-folder
echo "This is file placed in some-folder by auxiliary script" > file1
cd ..
cd other-folder
echo "This is file placed in other-folder by auxiliary script" > file2

My goal is to execute lines in auxiliary script (or just text file) as if those lines were written directly in main script. So if, for example, I invoke auxiliary.sh from inside a loop or function, all lines of auxiliary.sh will be executed in that loop or function.

2 Answers 2

4

Use the . command (alternately available as source in bash):

echo "This is the start of my main script"
# . ./auxiliary.sh
source ./auxiliary.sh
echo "This is the end of my main script"
Sign up to request clarification or add additional context in comments.

Comments

0

You can insert the bash script into another using the . command.

1 Comment

Can you given an example?

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.