In Jack Wallen’s tutorial for developers, he show how easy it is to set temporary environment variables in Linux.
Did you know that you can set temporary environment variables on the Linux operating system? With these variables, you can more easily work with scripts or even systemwide programs. And for developers, setting environment variables can come in handy.
For example, you might want to set a temporary variable for the version of your distribution you use, so downloading the correct application to install is much easier. Or, maybe you want to set a URL as an environment variable to work with a script. You could set the MY_SITE variable as, say, techrepublic.com, and use the variable in a bash script. Next, you might want that variable to change, so you could reset the temporary variable to a different site, which means you don’t have to edit your script. And if you set the environment variable, it will work with any script needing to call that variable.
So, how do you set an environment variable in Linux? Let me show you.
First, log into your Linux desktop or server and open a terminal window. Let’s set MY_SITE to techrepublic.com. For that, the command would be
export MY_SITE='techrepublic.com'
You can verify the variable was set properly by issuing the command
echo $MY_SITE
and you should see techrepublic.com printed. When you need to change that variable, run the export command with a different option in place of techrepublic.com. And that’s all there is to it.
This is a great way of setting variables that can be used by any type of script or application. As always, it’s best to work smarter and not harder.
Subscribe to TechRepublic’s How To Make Tech Work on YouTube for all the latest tech advice for business pros from Jack Wallen
Source of Article