never_had_a_name
never_had_a_name

Reputation: 93196

Global function inside in Bash?

I want to define a constant inside a function that could be used outside the function's scope.

function section {
   variable = "Hello"
}

echo variable

Is this possible?

Upvotes: 0

Views: 678

Answers (1)

ghostdog74
ghostdog74

Reputation: 342363

its already there for you to use. try to run it and see. Remember, no spaces between "=" sign when assigning variables

$ function section {  variable="Hello"; }
$ section
$ echo $variable
Hello

Upvotes: 4

Related Questions