Advanced Bash Environment Variables Tutorial

BASH is the shell installed on all 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"
echo $name


and then export it:

export name

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:

<?php
echo $_SERVER['name'];
?>


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.


  • 39 Users Found This Useful
Was this answer helpful?

Related Articles

List files and directories using SSH

In order to list all files and directories using an SSH client, you would need to execute the...

Create/Edit files and folders using SSH cmd line

There are various ways you can create a new file using the SSH command line.The easiest and most...

Move and copy files using SSH

Often you will need to move one or more files/folders or copy them to a different location. You...

Deleting files and folders via SSH

Sometimes you would need to remove a file or a folder from the system. To do so using SSH, you...

Extracting and creating archive files via SSH

Sometimes you would need to extract or create an archive file (i.e to install a script, you would...