cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Access notebooks parameters from a bash cell

jollymon
New Contributor II

How can I access a notebook parameter from a bash cell (%sh)? For python I use dbutils.widgets.get('param'), and for SQL I can use :param. Is there a something similar for bash?

1 ACCEPTED SOLUTION

Accepted Solutions

szymon_dybczak
Esteemed Contributor III

Hi @jollymon ,

I believe there is no direct way to do this. But maybe there are some workarounds though. You can try to read widgets in python and set those values as envrionment variables. Then you can use shell to read that variables. Something like below (except in python try to read widget value)

%python
import os
l =['A','B','C','D']
os.environ['LIST']=' '.join(l)print(os.getenv('LIST'))
%sh
for i in $LIST
do
  echo $i
done

 

View solution in original post

3 REPLIES 3

szymon_dybczak
Esteemed Contributor III

Hi @jollymon ,

I believe there is no direct way to do this. But maybe there are some workarounds though. You can try to read widgets in python and set those values as envrionment variables. Then you can use shell to read that variables. Something like below (except in python try to read widget value)

%python
import os
l =['A','B','C','D']
os.environ['LIST']=' '.join(l)print(os.getenv('LIST'))
%sh
for i in $LIST
do
  echo $i
done

 

That works. I suppose that's what I'll need to do then.

Thanks.

szymon_dybczak
Esteemed Contributor III

No problem, glad that it worked for you 

Join Us as a Local Community Builder!

Passionate about hosting events and connecting people? Help us grow a vibrant local communityโ€”sign up today to get started!

Sign Up Now