mirror of
https://github.com/Idnan/bash-guide.git
synced 2018-11-09 02:29:39 +01:00
~/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
1 changed files with 19 additions and 0 deletions
19
README.md
19
README.md
|
@ -1139,6 +1139,25 @@ function finish {
|
|||
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
|
||||
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 a new issue