Calling a script within a script that was run via nohup

253 views Asked by At

I have a script, which when I run to screen, works perfectly. The directory structure is as follows:

/home/username/processing/ScriptRunning
/home/username/processing/functions/include_me

In the script, it opens another script, which contains a function by simply doing this:

#!/bin/bash
#This is ScriptRunning script
. functions/include_me

Now when I call the script using the following nohup command:

nohup /home/username/processing/ScriptRunning

this is the output:

/home/username/processing/ScriptRunning: line 3: /home/username/functions/include_me: No such file or directory

It seems to be missing out the processing directory

I've altered the line within the ScriptRunning to have a full path, both hardcoded to /home/username/processing and also having this as a variable created by calling $(pwd), but the error is the same.

Am I really missing something so stupid?

1

There are 1 answers

1
Jürgen Hötzel On BEST ANSWER

This isn't a nohup issue. You are including a source file using a relative file name. Try:

. $(dirname ${BASH_SOURCE})/functions/include_me

to include a source file located relative to ${BASH_SOURCE}