<@ULVA73B9P> I am using Prefect 2.x. I used a scri...
# ask-marvin
t
@Marvin I am using Prefect 2.x. I used a script in my prefect.deployments.steps.run_shell_script in the push section of my prefect.yaml file. It reported that the “export” command was not found. What shell is used when running a multi-line script? How can I export an environment variable?
m
By default, Prefect's
run_shell_script
does not expand environment variables. You need to explicitly set
expand_env_vars: true
to allow environment variables to be expanded in your script. Here's an example configuration to export an environment variable correctly:
Copy code
yaml
- prefect.deployments.steps.run_shell_script:
    id: set-env
    script: |
        export MY_VAR="my_value"
        echo $MY_VAR
    stream_output: true
    expand_env_vars: true
Adding
expand_env_vars: true
ensures that your script can properly use the
export
command and other environment variable operations. For more details, you can refer to the Prefect 2.x documentation. If you have further questions or run into issues, feel free to ask!
t
@Marvin that isn’t what I asked. I am getting the error “FileNotFoundError: [Errno 2] No such file or directory: ‘export’” when I run the following pull step:
Copy code
- prefect.deployments.steps.run_shell_script:
      id: clone_vgt
      stream_output: true
      script: |
        export BRANCH=${BRANCH:-}
m
The issue you're encountering, where the
export
command is not found, typically arises because the default shell or environment in which the script is being run does not recognize the
export
command. Here's a solution to ensure that the script runs in a compatible shell (like bash):
Copy code
yaml
- prefect.deployments.steps.run_shell_script:
    id: clone_vgt
    stream_output: true
    script: |
      #!/bin/bash
      export BRANCH=${BRANCH:-}
    shell: /bin/bash
In this example, I've explicitly set the shell as
/bin/bash
by adding a shebang line (
#!/bin/bash
) and specifying the
shell
parameter. This ensures that your script runs in the bash shell, which supports the
export
command. If you want to explore more about this, here's the Prefect 2.x documentation. Feel free to ask if you have any more questions!