Linux Reader Access files and folders on Ext, UFS, HFS, ReiserFS, APFS file systems – from Windows
Linux Reader
Access files and folders on Ext, UFS, HFS, ReiserFS, APFS file systems – from Windows

What is a bash export command?

Here you will find out:

  • what a bash export command is
  • what the syntax and options of bash export command are
  • how to use an export bash script
  • when DiskInternals can help you

Are you ready? Let's read!

About a bash export command

According to POSIX, EXPORT is an attribute assigned to shell variables in correspondence to their unique names. In fact, the bash export command is one of many built-in commands for UNIX systems. It is used to identify variables and functions to be added to child processes. Interestingly, the bash export command supports only three options. This built-in bash command is important because it updates a current shell session with the updates to an environment variable.

The syntax and options of the bash export command

Bash export syntax:

Explanation:

-f = This is used when the names being referred to are shell functions. If the names are variables, there's no point introducing -f.

-n = Used to identify functions or variables that should not be exported.

-p = Prints all functions and variables marked for export.

Using an export bash script

Let's use the example below to explain how you can use the export command in advanced bash scripting.

In line 1, a new variable "a" is introduced for the string "diskint.com". Then in line 2, the bash echo command was used to print the content of the variable "a". In line 3, a new child shell is launched, and in line 4, the "a" variable is alone (not having any string).

From this example above, it is clear the child processes don’t inherit parent shell processes even when forked from the parent process. At this point, bash scripters introduce the export command. Hence, there is a new script, looking like the one below:

You can see that the export command was used to export values of the variable “a”, from the parent process to the new child process.

Using myvar to set values for variables

First, you have to set values for the variable using myvar. This can be achieved following this syntax:

Create a new shell by echoing bash.

A new bash shell is now active in your bash current session. The variable myvar will have no value if the export command is not introduced to push the value from the parent shell to the child shell; check below.

This will print a newline because myvar has no value.

Exit the shell with the exit command and return to the original bash session (parent shell) where myvar is defined.

Now echo myvar:

And enter your values for this variable.

Start a new shell session and introduce the export command:

And enter your values for this variable.

Open Linux files with DiskInternals Linux Reader

If you need to open Linux files in Windows, DiskInternals Linux Reader can help you out. DiskInternals Linux Reader does not support any algorithm, and it works on dual-boot PCs, as well as virtual machines. This software supports various files systems, including Ext2/3/4, ReiserFS, Reiser4, HFS, HFS+, FAT, exFAT, NTFS, ReFS, and UFS2.

DiskInternals Linux Reader features a smooth and easy to understand interface. It displays all the Linux partitions on your computer so you can open your files saved on those partitions.

FREE DOWNLOADVer 4.6, Win Upgrade to PROFrom $29.95

0.3574390411377