mirror of https://github.com/Idnan/bash-guide.git
~/bin directory to access scripts easily and keeping environment variables. (#49)
* keeping environment variables. Useful way to keep the environment variables. * Add a ~/bin directory to access scripts easily Useful way to access yours scripts easily.
This commit is contained in:
parent
b648976e22
commit
32eabdc339
19
README.md
19
README.md
|
@ -1139,6 +1139,25 @@ function finish {
|
||||||
trap finish EXIT
|
trap finish EXIT
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Saving your environment variables
|
||||||
|
|
||||||
|
When you do `export FOO = BAR`, your variable is only exported in this current shell and all its children, to persist in the future you can simply append in your `~/.bash_profile` file the command to export your variable
|
||||||
|
```bash
|
||||||
|
echo export FOO=BAR >> ~/.bash_profile
|
||||||
|
```
|
||||||
|
|
||||||
|
## Accessing your scripts
|
||||||
|
|
||||||
|
You can easily access your scripts by creating a bin folder in your home with `mkdir ~/bin`, now all the scripts you put in this folder you can access in any directory.
|
||||||
|
|
||||||
|
If you can not access, try append the code below in your `~/.bash_profile` file and after do `source ~/.bash_profile`.
|
||||||
|
```bash
|
||||||
|
# set PATH so it includes user's private bin if it exists
|
||||||
|
if [ -d "$HOME/bin" ] ; then
|
||||||
|
PATH="$HOME/bin:$PATH"
|
||||||
|
fi
|
||||||
|
```
|
||||||
|
|
||||||
# 4. Debugging
|
# 4. Debugging
|
||||||
You can easily debug the bash script by passing different options to `bash` command. For example `-n` will not run commands and check for syntax errors only. `-v` echo commands before running them. `-x` echo commands after command-line processing.
|
You can easily debug the bash script by passing different options to `bash` command. For example `-n` will not run commands and check for syntax errors only. `-v` echo commands before running them. `-x` echo commands after command-line processing.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue