Forrest logo
back to the set tool

set:tldr:f2e2a

set: Mark variables that are modified or created for export.
$ set -a
try on your machine

The "set -a" command is a shell builtin command in Unix-based operating systems.

When this command is used in a shell script, it enables automatic exporting of all variable assignments to the environment for subsequently executed commands. By default, only variables that are marked for export using the "export" command are passed to the environment of child processes.

By using "set -a", any variables that are assigned values in the script will be treated as if they were declared and exported using the "export" command.

Here is an example to demonstrate its usage:

#!/bin/bash

set -a

VAR1="Hello"
VAR2="World"

./some_script.sh

In this example, the "set -a" command ensures that VAR1 and VAR2 are automatically exported to the environment. The "./some_script.sh" command executes another script, and any variables from the parent script (VAR1 and VAR2 in this case) will also be available to the child script.

This can be useful when you want to ensure that child scripts or commands have access to specific variables without explicitly exporting them one by one.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the set tool