User Tools

Site Tools


en:cs:bash:variable

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 ''one'' to the console.
 +echo $foo
 + 
 +# This will print ''two'' to the console.
 +printvalue
 + 
 +# This will print ''one'' to the console.
 +echo $foo
 +</code>
 +
 +===== 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="Hello World."
 +
 +# Let's make it visible to all sub-processes by converting it to an environment variable:
 +export test_variable
 +</code>
 +
 +<wrap onlyprint>Taken from [[en:cs:bash:variable|UCH Wiki]].</wrap>
 +<wrap hide>
 +===== EDITOR NOTES =====
 +https://wiki.ulascemh.com/doku.php?id=en:cs:bash:variable
 +</wrap>