0

What I'm trying to achieve is manage cron jobs by saving them into my database, then writing one generic job which runs every minute and triggers the jobs saved in the database.

I found this piece of code in a code igniter library which I saw here

$env = getenv('CI_ENV');
foreach ($query->result() as $row) {
    $cmd = "export CI_ENV={$env} && {$row->command}";
    $output = shell_exec($cmd);
    //do other things
}

I do not understand what this line $cmd = "export CI_ENV={$env} && {$row->command}"; is really doing. I do not understand what export is doing there.

Valkay
  • 183
  • 3
  • 14
  • what is CI_ENV https://stackoverflow.com/questions/36051146/codeigniter3-why-would-serverci-env-ever-be-set-in-the-first-place and what is `shell export` https://stackoverflow.com/questions/7411455/what-does-export-do-in-shell-programming – splash58 Dec 10 '18 at 12:18
  • Have seen the links but I still don't understand why the export keyword is in that line. – Valkay Dec 10 '18 at 12:35
  • remove it if you don't need CI_env variable – splash58 Dec 10 '18 at 12:36

1 Answers1

1

export is a Linux command used to define a variable (and its value) in the BASH working "space". So, the line export CI_ENV={$env} is saying define a var named CI_ENV with a value of $env that I can use in BASH or other shell scripts.

DFriend
  • 8,869
  • 1
  • 13
  • 26