2

I have the following code in a databricks notebook:

%sh
export current_date=$(date '+%Y-%m-%d')
echo $current_date
> 2021-09-29

That works fine and for the current cell I can access and use the variable $current_date, however, if I try to call this variable in another cell I get empty as a result:

%sh
echo $current_date
>

This notebook might take more than one day to run, thus I want to define the current date when it starts running and use this value afterwards as a variable. How can I do that?

gnobre
  • 126
  • 7

1 Answers1

0

This is way Databricks has been configured. When you invoke a language magic command in cell , the command is dispatched to the REPL in the execution context for the notebook.Variables defined in that cell are not available in the REPL of another language/ another cell. REPLs can share state only through external resources such as files in DBFS or objects in object storage. In your case , You are trying to use magic command in both cells . This is expected behavioral . Hope this helps you to understand. Ref : https://docs.databricks.com/notebooks/notebooks-use.html#mix-languages