mirror of
https://gitea.com/mcereda/oam.git
synced 2026-02-09 05:44:23 +00:00
1.9 KiB
1.9 KiB
Bourne Again SHell
TL;DR
# Run a command or function on exit, kill or error.
trap "rm -f $tempfile" EXIT SIGTERM ERR
trap function-name EXIT SIGTERM ERR
# Disable CTRL-C
trap "" SIGINT
# Re-enable CTRL-C
trap - SIGINT
# Bash 3 and `sh` have no built-in means to convert case of a string, but the
# `awk`, `sed` or `tr` tools can be used instead.
echo $(echo "$name" | tr '[:upper:]' '[:lower:]' )
echo $(tr '[:upper:]' '[:lower:]' <<< "$name")
# Bash 5 has a special parameter expansion for upper- and lowercasing strings.
echo ${name,,}
echo ${name^^}
Files loading order
On startup:
- (if login shell)
/etc/profile - (if interactive and non login shell)
/etc/bashrc - (if login shell)
~/.bash_profile - (if login shell and
~/.bash_profilenot found)~/.bash_login - (if login shell and no
~/.bash_profilenor~/.bash_loginfound)~/.profile - (if interactive and non login shell)
~/.bashrc
Upon exit:
- (if login shell)
~/.bash_logout - (if login shell)
/etc/bash_logout
Check if a script is sourced by another
(return 0 2>/dev/null) && echo "this script is not sourced" || echo "this script is sourced"