In this project, you export a shell variable to make it globally recognized.
To demonstrate the use of the export command:
1. Type cat > testscript and press Enter.
2. Type echo $MY_VAR and press Enter.
3. Type Ctrl+d. You have created a simple shell script named testscript. Its only function is to display the value of the MY_VAR variable.
4. To make the script executable, type chmod ugo+x testscript, and press Enter.
5. Type MY_VAR=2, and press Enter.
6. Type echo $MY_VAR and press Enter to confirm the preceding operation. You see 2 on the screen.
7. Next look at the list of environment variables. Type printenv | more and press Enter.
Look carefully as you scroll through the output of the printenv command. You do not see the MY_VAR variable.
8. Type clear and press Enter to clear the screen.
9. Execute the shell script by typing ./testscript and pressing Enter. The script displays a blank line. This is because it does not have access to the shell variable MY_VAR.
10. Make the variable available to the script by typing export MY_VAR and pressing Enter.
11. Execute the script again by typing ./testscript and pressing Enter. This time, the value 2 appears. (See Figure 6-8 on the next page.)
12. Now look at your list of environment variables by typing printenv | more and pressing Enter. Again, look carefully as you scroll through the list. This time, you see MY_VAR listed.
13. Type clear and press Enter to clear the screen for the next project.
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.