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.
Related articles
- About a bash date command
- How to Access Linux Ext2 or Ext3 on Windows
- How to Access Ext4 from Windows
- How to Mount Ext4 on Windows for Free
- Mount Linux Drive on Windows for Free
- Bash Script: All You Need to Know
- An Algorithm: How to Create Bash While Loop
- Linux Shell: What You Need to Know at First
- 5 Basic Shell Script Examples for Your First Script
- Bash: How to Check if the File Does Not Exist
- Bash Time Command on Linux
- How to use bash get script directory in Linux
- How to Check Bash String Equality
- How to Use Linux Wait Command
- Bash: How to Loop Through Files in Directory
- 20 Examples of Bash Find Command
- Bash Cat Command in Examples
- Bash Script SSH: How to Use It
- Bash: A Script For User Input
- Linux ZSH: the basic you need to know
- Basic of Grep in Linux Shell Script
- Shell Script Cut: Basic You Need to Know
- Bash: How to Check if String Not Empty in Linux
- Bash: how to split strings in Linux
- Linux: Sudo in Bash Scripts
- Hello World Script in Bash
- A Linux bin/bash Shell
- Linux: New Line in Shell Script
- Linux: Bash String Ends With
- Linux: Bash Printf Examples
- Linux: Bash First Line
- Linux: $0 in a Shell Script
- Linux: A Bash Startup Script
- Linux: Write a Shell Script
- Shell Script: Replace String in File
- A crontab service shell script
- Bash and sh: is there any difference
- A Bash Dirname Command
- Linux: A Bash Source Command
- A Bash to Loop through Lines in File
- Linux: A Bash Linter
- A Bash Nested Loop
- A Bash Test Command
- Use a Shell Script to Send an Email
- A Bash Status of Last Command
- Linux: A Bash Basename Command
- Using Bash to Write to a File
- About Bash Language
- Bash for Loop in One Line
- AWK in a Bash Script
- Learn about useful bash scripts
- Learn about systemd startup script
- About chaining bash commands
- Learn about a bash error code
- Using a bash tee command
- Learn about a bash wait command
- Arch Linux install script
- About advanced bash scripting
- To run a shell script in Dockerfile
- About a bash UNTIL loop
- Learn about C shell script
- Learn about Korn shell scripting
- Using /usr/bin/env command
- Whether bash waits for command to finish
- Using bash if 0
- Using && in an IF statement in bash
- If you want to run shell script in background
- The disk you inserted was not readable by this computer error
- Learn about SFTP in bash scripting
- Learn to run Perl script in Linux
- Examples of using the Expect
- Copy command in shell scripts
- Shell script usage
- Install Oracle Database
- Here is everything you need to know about Bash for Windows
- Guide in Pictures
- How to Use Shell Script Sleep Command
- A Bash Multiline Command




