help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: crontab question


From: Greg Wooledge
Subject: Re: crontab question
Date: Mon, 9 Jan 2023 09:00:10 -0500

On Mon, Jan 09, 2023 at 11:00:59AM +0800, LinuxGuy wrote:
> Hello,
> 
> I put a command with arguments into crontab,
> 
> 0 * * * * /path/to/command arg1 arg2
> 
> 0 * * * * (/path/to/command arg1 arg2)
> 
> What are the differences between the above two?

In practice, nothing.

The first one becomes

  sh -c '/path/to/command arg1 arg2'

and the second one becomes

  sh -c '(/path/to/command arg1 arg2)'

The parentheses force the shell (sh) to run the command in a subshell
environment.  A subshell is essentially a forked child shell of the
main shell, and therefore it has its own private copies of variables,
its own private working directory and so on.

If there were commands before or after the subshell, then it might make
a difference.  However, since the *entire* script is inside of a single
subshell, the net effect is simply nothing.

The parentheses serve no purpose here, and may be removed.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]