en:cs:bash:variable
no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
| — | en:cs:bash:variable [2025/05/01 19:30] (current) – created ulascemh | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== Bash Variables ====== | ||
| + | ===== Local Variables ===== | ||
| + | |||
| + | <code bash> | ||
| + | foo=one | ||
| + | |||
| + | printvalue() { | ||
| + | local foo=two | ||
| + | |||
| + | echo $foo | ||
| + | } | ||
| + | |||
| + | |||
| + | # This will print '' | ||
| + | echo $foo | ||
| + | |||
| + | # This will print '' | ||
| + | printvalue | ||
| + | |||
| + | # This will print '' | ||
| + | echo $foo | ||
| + | </ | ||
| + | |||
| + | ===== Environment Variables ===== | ||
| + | |||
| + | One feature we will use for Scope is the system that exists in all Unix systems. For example, when we call a program in a script, all environment variables are copied into the scope of that program. In short, the variables we define in the called script can only be accessed if they are environment variables. | ||
| + | |||
| + | <code bash> | ||
| + | # create a new variable and set it: | ||
| + | # -> This is a normal variable, not an environment variable! | ||
| + | test_variable=" | ||
| + | |||
| + | # Let's make it visible to all sub-processes by converting it to an environment variable: | ||
| + | export test_variable | ||
| + | </ | ||
| + | |||
| + | <wrap onlyprint> | ||
| + | <wrap hide> | ||
| + | ===== EDITOR NOTES ===== | ||
| + | https:// | ||
| + | </ | ||
en/cs/bash/variable.txt · Last modified: 2025/05/01 19:30 by ulascemh
