JAN
JAN

Reputation: 21855

exec throws "no such file or directory" but folder exists and so does the file

I'm using the following exec command:

MainFolder is the main folder inside it mainScript.sh and settings folder

mainScript.sh (Located in MainFolder) :

....
...
...
exec "../settings/helper.sh"

The file helper.sh is located one folder before the current directory , in settings folder but exec throws no such file or directory.

Any idea how to fix this ?

Upvotes: 0

Views: 1449

Answers (1)

ufopilot
ufopilot

Reputation: 3975

You have to declare the variable MAINFOLDER in your script mainScript.sh

MAINFOLDER=$(dirname $(readlink -f $0))

and call any script relative to $MAINFOLDER

if settings is in $MAINFOLDER

exec "${MAINFOLDER}/settings/helper.sh"

if settings is located one folder before

exec "${MAINFOLDER}/../settings/helper.sh"

Upvotes: 1

Related Questions