Languages
[Edit]
EN

Bash - create local variable in function

0 points
Created by:
Theodora-Battle
528

In this article, we would like to show you how to create local variable in function using Bash.

Quick solution:

Hint: it is possible to create and initialize variable by using local variable_name="Some value here...".

 

Practical example

Edit

In this example, we use local keyword to create a local variable inside a function.

When we increment and print the function inside the for loop within the function, it works fine. However, when we try to use it outside the function, it can't be found since it's outside the scope.

1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join