Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
262 views
in Technique[技术] by (71.8m points)

linux - My shell script stops after exec

I'm writing a shell script that looks like this:

 for i in $ACTIONS_DIR/*
    do
            if [ -x $i ]; then
                    exec $i nap
            fi
    done

Now, what I'm trying to achieve is to list every file in $ACTIONS_DIR to be able to execute it. Each file under $ACTIONS_DIR is another shell script.

Now, the problem here is that after using exec the script stops and doesn't go to the next file in line. Any ideas why might this be?

question from:https://stackoverflow.com/questions/65949732/why-does-my-loop-ends-after-first-execution

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

exec replaces the shell process. Remove it if you only want to call the command as a subprocess instead.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...