How to Setup Bash
Configuration Items
Configuring Bash Consists of 4 main elements
- Entrypoint
- Environment Vars
- Aliases
- Path
The Entrypoint is the file that gets loaded everytime Bash Starts. This will most likely be
- $HOME/.bash_profile
- $HOME/.bashrc
The rest of the guide will use .bash_profile
The Environment Variabls can be set with a global variable BASH_ENV
that will source this file everytime the terminal starts.
You can use .bash_profile
to source env files at startup too!
**Use export
so all commands and sub shells inherit the variables,
otherwise they can only be used in the file or shell they are being ran in.
#!/usr/bin/env bash
## Local Shell/file only
LOCAL_VAR='This is local'
## Exported Variable available in all Shells/SubShells
export GLOBAL_VAR='This is Global'
In your bash_profile you would source it at the top like this
#!/usr/bin/env bash
source $HOME/bash/env.sh
Bash Alias are ways for you to make shortcuts and combine multiple commands together. You can also use functions!
Here are a few
#!/usr/bin/env bash
alias c="clear"
alias ll="ls -la"
function sb(){
echo "Reloading .bash_profile to update env...."
source ~/.bash_profile
}
function showPath(){
if [[ -z "$1" ]]; then
echo -e $(echo -e $PATH | sed 's/:/\\n/g');
else
echo -e $(echo -e $PATH | sed 's/:/\\n/g') | grep $1
fi
}
function findFile(){
find . -type f -iname "*$1*"
}
function encode(){
echo -n "$1" | base64
echo ""
}
function decode(){
echo -n "$1" | base64 -d
echo ""
}
In your bash_profile you would source it at the top like this
source env files first so you can use them in alias commands
#!/usr/bin/env bash
source $HOME/bash/env.sh
source $HOME/bash/alias.sh
Add a folder we can drop exe files in and access them in our bash terminal, Lets call it bin
mkdir -p $HOME/bin
Now we need to add it to the shells path using the PATH
variable.
#!/usr/bin/env bash
source $HOME/bash/env.sh
source $HOME/bash/alias.sh
export PATH=$HOME/bin:${PATH}
# Can also source other locations
export PATH=$HOME/AppData/Local/Programs/Python/Python312/Scripts:${PATH}
Can also make a path.sh file if you want to organize it like that.
#!/usr/bin/env bash
export PATH=$HOME/bin:${PATH}
export PATH=$HOME/AppData/Local/Programs/Python/Python312/Scripts:${PATH}
#!/usr/bin/env bash
source $HOME/bash/env.sh
source $HOME/bash/path.sh
source $HOME/bash/alias.sh
...