简体   繁体   中英

Bash script stops after including /etc/init.d/functions

I am creating my first init script on CentOS 7. And I want to run one process as deamon at this script, and trying to use daemon function from /etc/init.d/functions file, but when I include this script execution stops.

Suppose my created file is "/etc/init.d/UpdateScript" If I write:

echo "Script start"
. /etc/init.d/functions
echo "After add functions"

So after command: /etc/init.d/UpdateScript start

I have only "Script start" as output. But if I comment "# . /etc/init.d/functions" them I have "After add functions" too but of course "daemon: command not found". What is the reason of that strange behavior? How to fix it?

/etc/init.d/functions ends with return 0 . When you source (or . ) a shell script you're effectively replacing the source call with its content. Since there's a return there, the execution does not continue after it, and echo "After add functions" is never executed.

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