Quick startexport
Command to export variables to the child process
Thisexport
Commands are used to export variables to the child process.
What does it mean?
Suppose you define a variable TEST in this way:
TEST="test"
You can print its value using the following commandecho $TEST
:
But if you try to define the Bash script in the filescript.sh
Use the above command:
Then you setchmod u+x script.sh
Then execute the script./script.sh
, Thisecho $TEST
About to print nothing!
This is because in BashTEST
Variables are defined locally in the shell. When a shell script or other command is executed, a sub-shell program will be launched to execute the script, and the sub-shell program does not contain the current shell local variables.
In order to make the variable available, we need to defineTEST
not like this:
TEST="test"
But this:
export TEST="test"
Try it out, then run./script.sh
"Test" should now be printed:
Sometimes you need to append some content after the variable. Usually throughPATH
Changing. You use the following syntax:
export PATH=$PATH:/new/path
Commonly usedexport
When you create a new variable in this way, also when you.bash_profile
or.bashrc
Use Bash's configuration file, or.zshenv
With Zsh.
To delete variables, use-n
Options:
export -n TEST
callexport
If there are no options, all exported variables will be listed.
Thisexport
This command can be used in Linux, macOS, WSL and wherever you have a UNIX environment
Download mine for freeLinux Command Manual
More cli tutorials:
- Bash shell
- Introduction to Bash Shell Script
- Fish shell
- Shell, monitor file content
- How to exit Vim
- UNIX editor
- UNIX file system commands
- Unix Shell Tutorial
- How to set an alias in macOS or Linux Shell
- Homemade practical guide
- How to fix XCRUN invalid active developer path error in MacOS
- Getting Started
- Introduction to Linux
- How to find the process that is using the port
- Linux command: mkdir
- Linux command: cd
- Linux command: pwd
- Linux command: rmdir
- Linux command: ls
- Linux command: mv
- Linux command: cp
- Linux commands: less
- Linux command: tail
- Linux command: touch
- Linux command: cat
- Linux command: find
- Linux command: ln
- Linux command: ps
- Linux command: echo
- Linux command: top
- Linux command: kill
- Linux command: killall
- Linux command: alias
- Linux command: job
- Linux command: bg
- Linux command: fg
- Linux command: Type
- Linux command: where
- Linux command: whoami
- Linux command: who
- Linux command: clear
- Linux command: su
- Linux command: sudo
- Linux command: chown
- Linux command: chmod
- Linux command: passwd
- Linux command: open
- Linux command: wc
- Linux commands: history
- Linux command: du
- Linux command: umask
- Linux command: grep
- Linux command: man
- Linux command: uname
- Linux commands: sort
- Linux command: uniq
- Linux command: diff
- Linux command: nohup
- Linux command: df
- Linux command: xargs
- Linux command: gzip
- Linux command: gunzip
- Linux command: ping
- Linux command: traceroute
- Linux command: tar
- Linux command: export
- Linux command: crontab
- Linux command: dirname
- Linux command: base name
- Linux command: printenv
- Linux command: env
- A short guide to the ed editor
- vim short guide
- A brief guide to emacs
- A brief guide to Nano
- Linux, no space left on the device
- How to use Netcat