https://github.com/danass/add-to-path
Easily Add or Remove the Current Directory to the $PATH in Bash
https://github.com/danass/add-to-path
bash bash-script environment-variables path
Last synced: 11 days ago
JSON representation
Easily Add or Remove the Current Directory to the $PATH in Bash
- Host: GitHub
- URL: https://github.com/danass/add-to-path
- Owner: danass
- License: gpl-3.0
- Created: 2023-08-01T14:17:38.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-29T16:55:44.000Z (about 1 year ago)
- Last Synced: 2025-03-12T13:41:49.395Z (10 months ago)
- Topics: bash, bash-script, environment-variables, path
- Language: Shell
- Homepage:
- Size: 25.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Easily Add or Remove the Current Directory to the `$PATH` in Bash
This simple utility allows you to quickly add or remove the **current directory** to the global `$PATH` in Bash, making it accessible from anywhere.
To use this tool, simply add the content of the [atp.sh](https://github.com/danass/Add-to-path/blob/main/atp.sh) script to your **~/.bashrc** file, then source the file to activate the function.
## Usage Instructions
### 1. Adding the Current Directory to `$PATH`
To temporarily add the current directory to the `$PATH`, run:
```bash
user@machine:~/current-directory$ atp .
```
Now, when you check `$PATH`, you should see `/home/user/current-directory` (or the directory you are currently in) added to the end of the path:
```bash
user@machine:~/current-directory$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/user/current-directory
```
### 2. Removing the Current Directory from `$PATH`
To remove the current directory from the `$PATH`, use:
```bash
user@machine:~/current-directory$ atp -r .
```
After running this command, the `$PATH` will return to its previous state, without the current directory:
```bash
user@machine:~/current-directory$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
```
---
### And that’s it!
With just two simple commands, you can add or remove the current directory from your `$PATH`. This is especially useful for testing or running scripts without needing to permanently modify the global `$PATH`.