# Environment variables

## What is it?

On the linux system we technically have 2 variables **Environment** and **Shell**

### Environment variables

An **environment variable** is a special kind of variable that is **copied from the system into a process** when it starts. It lives as a **process-wide variable** inside that process.

### Shell variables

used in shell scripts for many functionalities like storing data and information, taking input from users, printing values that are stored

## Viewing and modifying

To view or modify the environment variables we use `env`

You will see some uppercase strings like HOME, PATH, SHELL and etc. Those are default environment variables

### view ALL variables

Use `set` to view all variables you can do with `more` or `less`

### Changing variables

To change variables simply type the parameter and the value in your terminal

```bash
$ set | grep HISTSIZE #HISTSIZE is storing the past commands and change to 0 makes it store nothing
  HISTSIZE=1000
$ HISTSIZE=0
$ set | grep HISTSIZE
  HISTSIZE=0
```

**Make it permanent**

`export` is which make things permanent

save the original first :)

```bash
$ echo $HISTSIZE > ~/OrgvalueofHISTSIZE.txt #save the original value
$ set > ~/savedvalues.txt #saves all original values
```

```bash
$ HISTSIZE=0
$ export HISTSIZE #and then it will be permanet
```

## Cool variables

### PS1

Set the shell prompt as you need

* `\u` The name of the current user
* `\h` The hostname
* `\w` The base name of the current working directory

```bash
┌──(vix㉿D3sKt0P-90000)-[~]
└─$ PS1="My Shell $"

My Shell $
My Shell$PS1='\uก็็\h|\w $'

vixก็็D3sKt0P-90000|~ $cd Music
vixก็็D3sKt0P-90000|~/Music $
```

### PATH

This is the one of most important variables

Most of the commands stored in **sbin** or **bin** files so that if you type `ls` , `cd` and things like that will work

```bash
$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
```

This will be really useful when installing new tools, let’s say you downloaded a cool tool from github and every time you need to go to the directory in order to use it, so why not add it to PATH

**DO NOT DO THINGS LIKE:** ~~`$ PATH=/root/cooltool`~~ it will replace all of the paths inside

```bash
$ PATH=$PATH:/root/cooltool
$ echo $PATH
/usr/local/sbin:usr/local/bin:/usr/sbin:/sbin/bin:/root/cooltool
```

### Define your own variable

```bash
$ MYVARIABLE="Hello still learning"
$ echo $MYVARIABLE
Hello still learning

$ unset  MYVARIABLE #to clear/unset the value of the variable
$ echo $MYVARIABLE
#blank
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://vix-w1zzer.gitbook.io/vixwizzer/notes/linux/environment-variables.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
