Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

7
  • Hmmm, if I have to make a modification like this to crontab, I might as well just create a file called ~/.zshrc-java since I have a lot of dotfiles, organized by functionality (~/.zshrc-git, ~/.zshrc-p4, ~/.zshrc-work, ~/.zshrc-home). Commented Mar 23, 2021 at 22:01
  • 1
    ... or add JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/jre/ at the top of your crontab, instead of setting it for each job. The point of this answer is to avoid duplicating the definition of a variable (since you asked about "sharing") and, given that there is no profile/initialization file that both sh and zsh read by default, a clean way to do that is by letting zsh define the environment for the cron job. Commented Mar 23, 2021 at 22:10
  • I didn't realize you could do that. That's the simplest solution, though I need to use that sparingly. Self-contained single lines are easier to debug. Commented Mar 23, 2021 at 22:44
  • I'll mark this answer correct though I'll just add an extra line to your answer. Hope you don't mind. Commented Mar 23, 2021 at 22:45
  • 1
    I removed the numbered list to make clear that the three paragraphs correspond to three distinct solutions. I'd guess the "best" approach is ultimately a matter of taste. Commented Mar 23, 2021 at 22:56