Set the variable before a command, on the same line: $ SOMETHING="a value" env Set the variable on its own line, then use it anywhere: $ SOMETHING="some value" There are two ways to set an environment variable on the fly: When you close Terminal or type "exit", your session is closed and that context and data is lost. When you log in, you start a new session, in which your commands will be recorded and other contextual information will be maintained. Note: The term "session" refers to the state of being logged in to a computer's command line interface. You can do this on the fly, so that your changes only affect the current command or the current session, or you can make the changes more permanent so that they stick between sessions. While there are several environment variables that are set for you automatically, you can also set your own or modify existing variables. How to Change your Command Line Environment If you're doing this on a Mac, the value will probably be something like /Users/bob. It should say something like /home/ubuntu, where ubuntu will be replaced by your username. Type env, hit enter, and find the value for HOME. You can see exactly what variables have been set, along with their values, by running env at the command line. When you log in to the command line, a variety of environment variables are automatically set. In other words, running cd $HOME is the same as running cd /home/ubuntu, assuming your home directory is /home/ubuntu. In the command cd $HOME, the $HOME part is a reference to the HOME variable, and is replaced by the path to your home directory when the command is run. In programming, variables are used to store data and to be able to reference and retrieve that data at a later point using a name. Another way of providing context is through something called environment variables. In the last chapter, we talked about how your "current directory" provides context for commands you run.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |