# 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

```sh
export VAR_NAME=value
```

#### Common Options

* **Set an environment variable:**
    
    ```sh
    export PATH=$PATH:/new/path
    ```
    
* **Export a variable with spaces in its value:**
    
    ```sh
    export MY_VAR="This is a value"
    ```
    

#### Useful Commands and Examples

1. **Set and export a variable:**
    
    ```sh
    export VAR_NAME="value"
    ```
    
2. **Append to an existing PATH variable:**
    
    ```sh
    export PATH=$PATH:/usr/local/bin
    ```
    
3. **Export multiple variables:**
    
    ```sh
    export VAR1="value1" VAR2="value2"
    ```
    
4. **Export a variable for a specific command:**
    
    ```sh
    VAR_NAME=value command
    ```
    
5. **List all exported variables:**
    
    ```sh
    export -p
    ```
    
6. **Unset an environment variable:**
    
    ```sh
    unset VAR_NAME
    ```
    

#### Example Usage in Scripts

* **Setting an environment variable in a script:**
    
    ```sh
    #!/bin/bash
    export DATABASE_URL="mysql://user:password@localhost/db"
    ```
    
* **Using** `export` in a pipeline:
    
    ```sh
    export MY_VAR="hello"
    some_command | another_command
    ```
    

#### Additional Information

* **Help option for** `export`:
    
    ```sh
    help export
    ```
    
* **View** `export` manual page:
    
    ```sh
    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`.
