Generally improved notes on shells

This commit is contained in:
Michele Cereda
2022-10-16 01:53:24 +02:00
parent 07632ba5a2
commit ad0c06011b
2 changed files with 78 additions and 20 deletions

View File

@@ -3,14 +3,21 @@
## TL;DR
```sh
# Declare functions.
functionName () {}
function functionName {}
# Declare functions on a single line.
functionName () { command1 ;; command N ; }
# 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
# Disable CTRL-C.
trap "" SIGINT
# Re-enable CTRL-C
# Re-enable CTRL-C.
trap - SIGINT
# Bash 3 and `sh` have no built-in means to convert case of a string, but the
@@ -23,7 +30,7 @@ echo ${name,,}
echo ${name^^}
```
## Files loading order
## Startup files loading order
On startup:
@@ -39,6 +46,10 @@ Upon exit:
1. (if login shell) `~/.bash_logout`
1. (if login shell) `/etc/bash_logout`
## Functions
A function automatically returns the exit code of the last command in it.
## Check if a script is sourced by another
```sh