Skip to main content

Command Palette

Search for a command to run...

Cheat Sheet #day62 - export

Published
1 min read
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

  1. Set and export a variable:

     export VAR_NAME="value"
    
  2. Append to an existing PATH variable:

     export PATH=$PATH:/usr/local/bin
    
  3. Export multiple variables:

     export VAR1="value1" VAR2="value2"
    
  4. Export a variable for a specific command:

     VAR_NAME=value command
    
  5. List all exported variables:

     export -p
    
  6. 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.

Cheat Sheets

Part 1 of 50

These cheat sheets are designed to be quick reference materials, offering condensed information, tips, and best practices in a easy to understand format.

More from this blog

Cloud Tuned

621 posts

Your starting point for anything cloud: AWS, Azure, GCP, Serverless, Architecture, Hybrid Cloud, Systems Design and other Information Technology topics.