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

Pew Pew madafakas!

Access files and folders on Ext, UFS, HFS, ReiserFS, or APFS file systems from Windows
Last updated: Jul 29, 2021

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:

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.

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:

Introduce the export command

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:

Using myvar to set values for the variable

Create a new shell by echoing bash.

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.

Myvar has no value

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:

Echo myvar

And enter your values for this variable.

Start a new shell session and introduce the export command:

Start a new shell session

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.

Related articles

FREE DOWNLOADVer 4.22, WinUpgrade to PROFrom $29.95

Please rate this article.
51 reviews