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.