3

I am running a Perl script in a loop in a shell script:

  while [ $currentDate -le $toDate ]; do
    // code here...
    exec /users/my_user/script_name $currentDate
    // code here...
  done

I have confirmed the while-loop loops. However, after one run of the Perl script, the while-loop ends.

Could someone please shed some light on this?

3 Answers 3

11

You're using exec. exec replaces the shell process with the new program. You probably want to just remove the exec keyword.

exec [-cl] [-a name] [command [arguments ...]] [redirection ...]

Replace the shell with the given command.

Execute COMMAND, replacing this shell with the specified program. ARGUMENTS become the arguments to COMMAND.

Sign up to request clarification or add additional context in comments.

Comments

1

Change:

exec /users/my_user/script_name $currentDate

To:

/users/my_user/script_name $currentDate

Comments

1

The issue you are having is caused by

exec /users/my_user/script_name $currentDate

what the exec causes is for the perl script that you are calling replaces the current program with the new one and keeps the current PID.

If you remove the exec from the line it will allow the program to spawn properly and keep the shell running as you expect.

1 Comment

@daxim sorry in my hurry to answer the question I missed that but I have updated my answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.