Forrest logo
back to the declare tool

declare:tldr:bc39b

declare: Declare a global variable within a function with the specified value.
$ declare -g ${variable}="${value}"
try on your machine

This command is used to declare a global variable in a shell script.

Here's a breakdown of the command:

  • declare: This is a built-in command in most shell environments, including Bash. It is used to declare variables and set their attributes.
  • -g: This option is used to declare a variable as global, meaning it can be accessed from anywhere within the script or in any subshells.
  • ${variable}: This is the name of the variable you want to declare. It should be replaced with the actual variable name.
  • "${value}": This is the value assigned to the variable. It can be any valid string or expression. It should be replaced with the actual value you want to assign to the variable.

Overall, the command declare -g ${variable}="${value}" declares a global variable with the given name and assigns the specified value to it.

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 declare tool