Home > Software design >  why assign python command to sh var? what does this file do? [closed]
why assign python command to sh var? what does this file do? [closed]

Time:09-29

  • anyone knows what this last line does in this .sh file?
  • why assign var to itself with python command?

how python file (bigquery library) has access to json file name?

DAY=2021-01-01
GOOGLE_APPLICATION_CREDENTIALS=file.json
GOOGLE_APPLICATION_CREDENTIALS=$GOOGLE_APPLICATION_CREDENTIALS python3 run_calc_bq.py table_name $DAY $DAY

Thank you :)

CodePudding user response:

It's setting the value of GOOGLE_APPLICATION_CREDENTIALS in the environment of the Python command, but not in the shell itself. Repeating the variable name is a bit odd. If you were fine with adding the variable to the environment for all commands, you could write

DAY=2021-01-01
export GOOGLE_APPLICATION_CREDENTIALS=file.json
python3 run_calc_bq.py table_name "$DAY" "$DAY"

If you really do want it in just the Python command's environment, you could use a much shorter variable name.

DAY=2021-01-01
x=file.json
GOOGLE_APPLICATION_CREDENTIALS=$x python3 run_calc_bq.py table_name "$DAY" "$DAY"

CodePudding user response:

The variable GOOGLE_APPLICATION_CREDENTIALS is declared in the parent script, but it is not exported.

In order to make it available to the child script, you have two options:

Export it

# export to all child processes
export GOOGLE_APPLICATION_CREDENTIALS

Or prepend it to the command line

# export to this specific command
GOOGLE_APPLICATION_CREDENTIALS=$GOOGLE_APPLICATION_CREDENTIALS python3 ...
  • Related