循环中的Perl脚本在一次运行后结束

时间:2013-06-18 20:21:34

标签: perl shell

我在shell脚本的循环中运行Perl脚本:

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

我已确认while-loop次循环。但是,在运行一次Perl脚本后,while-loop结束。

有人可以对此有所了解吗?

3 个答案:

答案 0 :(得分:11)

您正在使用execexec用新程序替换shell进程。您可能只想删除exec关键字。

  

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

     

用给定的命令替换shell。

     

执行COMMAND,用指定的程序替换此shell。       ARGUMENTS成为COMMAND的参数。

答案 1 :(得分:1)

变化:

exec /users/my_user/script_name $currentDate

要:

/users/my_user/script_name $currentDate

答案 2 :(得分:1)

您遇到的问题是由

引起的
exec /users/my_user/script_name $currentDate

exec导致的是你正在调用的perl脚本用新的脚本替换当前程序并保留当前的PID。

如果从行中删除exec,它将允许程序正确生成并保持shell按预期运行。