You can set your own environment variables directly from the bash shell.This section shows how to create your own environment variables and reference them from your interactive shell or shell script program.
Setting local environment variables
Once you start a bash shell (or spawn a shell script), you’re allowed to create local variables that are visible within your shell process. You can assign either a numeric or a string value to an environment variable by assigning the variable to a value using the equal sign:
That was simple! Now any time you need to reference the value of the test environment variable, just reference it by the name $test.
If you need to assign a string value that contains spaces, you’ll need to use a single quotation
mark to delineate the beginning and the end of the string:
Without the single quotation marks, the bash shell assumes that the next character is another command to process. Notice that for the local environment variable I defined, I used lower-case letters, while the system environment variables we’ve seen so far have all used upper-case letters.
This is a standard convention in the bash shell. If you create new environment variables, it is recommended (but not required) that you use lower-case letters. This helps distinguish your personal environment variables from the scores of system environment variables.
Once you set a local environment variable, it’s available for use anywhere within your shell process.
However, if you spawn another shell, it’s not available in the child shell:
In this example I started a child shell. As you can see, the test environment variable is not available in the child shell (it contains a blank value). After I exited the child shell and returned to the original shell, the local environment variable was still available.
Similarly, if you set a local environment variable in a child process, once you leave the child process the local environment variable is no longer available:
The test environment variable set in the child shell doesn’t exist when I go back to the parent shell.
Setting global environment variables
Global environment variables are visible from any child processes created by the process that sets the global environment variable. The method used to create a global environment variable is to create a local environment variable, then export it to the global environment.
This is done by using the export command:
After exporting the local environment variable test, I started a new shell process and viewed the value of the test environment variable. This time, the environment variable kept its value, as the export command made it global.
Adobe Photoshop Related Tutorials
|Adobe Flex Tutorial|
Adobe Photoshop Related Interview Questions
|Adobe PageMaker Interview Questions||Adobe Indesign Interview Questions|
|Adobe AEM/CQ Interview Questions||Adobe Flex Interview Questions|
|Adobe ColdFusion Interview Questions||Adobe Lightroom Interview Questions|
|Adobe After Effects Interview Questions||Adobe Fireworks Interview Questions|
|Adobe Analytics Interview Questions|
All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.