Advanced Bash Environment Variables Tutorial
SSH Advanced Bash Environment Variables
BASH is the shell installed on all SiteGround servers by default.
It is a very powerful shell language and is an invaluable tool when working with Linux systems.
Under bash and almost all other shells, the user can define environment variables, which are stored internally as ASCII strings.
One of the handiest things about environment variables is that they are a standard part of the UNIX process model, which means that once an environment variable is set, it can be read by any subsequent process we run.
Let’s try this and set an environment variable called $name with value “My Full Name”:
name="My Full Name";
then export it:
The variable $name is now in the environment list of variables and can be accessed by other processes. Let’s try this with a sample php script:
When run on command line (using: php script.php) you will see that PHP will now print “My Full Name”.
This is very useful when you need to troubleshoot certain php (and not only) scripts which requires input from the visitor (for example via a form).
Without using environment variables however it will not be possible to be tested on a command line.