我在shell脚本的循环中运行Perl脚本:
while [ $currentDate -le $toDate ]; do
// code here...
exec /users/my_user/script_name $currentDate
// code here...
done
我已确认while-loop
次循环。但是,在运行一次Perl脚本后,while-loop
结束。
有人可以对此有所了解吗?
答案 0 :(得分:11)
您正在使用exec
。 exec
用新程序替换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按预期运行。