简体   繁体   中英

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 ?

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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM