Cheat Sheet #day62 - export
export
Command Cheatsheet
The export
command in Unix-like systems is used to set environment variables, making them available to subprocesses. Here's a quick reference guide:
Basic Syntax
export VAR_NAME=value
Common Options
Set an environment variable:
export PATH=$PATH:/new/path
Export a variable with spaces in its value:
export MY_VAR="This is a value"
Useful Commands and Examples
Set and export a variable:
export VAR_NAME="value"
Append to an existing PATH variable:
export PATH=$PATH:/usr/local/bin
Export multiple variables:
export VAR1="value1" VAR2="value2"
Export a variable for a specific command:
VAR_NAME=value command
List all exported variables:
export -p
Unset an environment variable:
unset VAR_NAME
Example Usage in Scripts
Setting an environment variable in a script:
#!/bin/bash export DATABASE_URL="mysql://user:password@localhost/db"
Using
export
in a pipeline:export MY_VAR="hello" some_command | another_command
Additional Information
Help option for
export
:help export
View
export
manual page:man bash
This cheatsheet covers the basic usage and common scenarios for the export
command. For more detailed information, refer to the man
page or use help export
.
Subscribe to my newsletter
Read articles from Cloud Tuned directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by