1

Say I have a script named "mydailyscript" containing the following:

#!/bin/bash if [ ! -z $MYDAILYLOG]; then exec 1>$MYDAILYLOG fi echo This script ran on $(date)

and I then copy this script to /etc/cron.daily.

Where do I define the environment variable, MYDAILYLOG? i.e. MYDAILYLOG=/var/log/mydailylog

Do I append a line to /etc/environment?

sudo echo "MYDAILYLOG=/var/log/mydailylog" >> /etc/environment

1
  • I tried appending to /etc/environment and got a "permission denied" error.env
    – AWM
    Jul 18, 2019 at 17:42

1 Answer 1

0

If you want to add a variable to for all users of your system, you add it in the /etc/environment. It is global environment file.

You want to define variable for your current script only, you can use the path as a regular variable before the place where you have used the variable or you want to add the path as a variable, you can use export also.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .