0

Consider the following anacrontab file:

1 0 bob-job /home/bob/script.sh

I know I can set variables like this:

FOO=bar
1 0 bob-job /home/bob/script.sh

However, can I set a variable just for the bob-job line?

I know I can do:

FOO=bar
1 0 bob-job /home/bob/script.sh
FOO=

... but this is not equivalent because it clobbers the existing value of FOO, if any (from the parent environment of anacron), and setting FOO= to empty is not also equivalent to unset.

BeeOnRope
  • 547
  • What are you trying to do with this script? Is FOO being used anywhere else in the script? If not, then why do you need to unset it? If you need to do it for some other reason, then use unset FOO. – Nasir Riley Apr 08 '20 at 02:28
  • 1
    Consider https://unix.stackexchange.com/q/56444/117549 – Jeff Schaller Apr 08 '20 at 02:40

1 Answers1

2

You could use the env utility:

1 0 bob-job    env FOO=bar /home/bob/script.sh

The env utility sets one or several environment variables (or clears the environment with -i) and executes the given utility (your script) with the modified environment.

See man env on your system.

Kusalananda
  • 333,661