Files
homelab/active/software_bash/bash.md
ducoterra 7b93f740ec
Some checks failed
Reese's Arch Toolbox / build-and-push-arch-toolbox (push) Failing after 2m40s
Podman DDNS Image / build-and-push-ddns (push) Failing after 5s
wyoming updates, borg manual, fedora kscreen, bambu wifi, vscode pylance, stable diffusion
2025-05-23 13:49:03 -04:00

2.0 KiB

Bash Tips

bashrc

Eternal History

# Eternal bash history.
# ---------------------
# Undocumented feature which sets the size to "unlimited".
# http://stackoverflow.com/questions/9457233/unlimited-bash-history
export HISTFILESIZE=-1
export HISTSIZE=-1
export HISTTIMEFORMAT="[%F %T] "
# Change the file location because certain bash sessions truncate .bash_history file upon close.
# http://superuser.com/questions/575479/bash-history-truncated-to-500-lines-on-each-login
export HISTFILE=~/.bash_eternal_history
# Force prompt to write history after every command.
# http://superuser.com/questions/20900/bash-history-loss
PROMPT_COMMAND="history -a; $PROMPT_COMMAND"

Global bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
    . /etc/bashrc
fi

User Environment

# User specific environment
if ! [[ "$PATH" =~ "$HOME/.local/bin:$HOME/bin:" ]]; then
    PATH="$HOME/.local/bin:$HOME/bin:$PATH"
fi
export PATH

User Aliases

Allows custom aliases in ~/.bashrc.d

# User specific aliases and functions
if [ -d ~/.bashrc.d ]; then
    for rc in ~/.bashrc.d/*; do
        if [ -f "$rc" ]; then
            . "$rc"
        fi
    done
fi
unset rc

Check if executable exists

if command -v aws 2>&1 >/dev/null
then
    echo "aws command found"
else
    echo "aws could not be found"
fi

Check if file exists

FILE=/etc/resolv.conf
if [ -f "$FILE" ]; then
    echo "$FILE exists."
else 
    echo "$FILE does not exist."
fi

Check if last command exit code was zero

cat /i/do/not/exit

if [ $? -eq 0 ]
then
  echo "Success."
else
  echo "Failure." >&2
fi