Tool.Yun
Strumenti utili per gli sviluppatori
Decodificatore di codici QR
Generatore di codice QR
Generatore di codice QR WiFi
Generatore di codici a barre
Generatore di informazioni di contatto QR
Lettore di codici a barre
Validatore GTIN
tools.epc-qrcode-generator.name
Codificatore/decodificatore di array esadecimali Base64
Codificatore/decodificatore di stringhe Base64
Consumo energetico e spese del computer
Convertitore dBm mW
Convertitore di base intera
Convertitore di caratteri Unicode in entità Java
Convertitore di coordinate geografiche
Convertitore di file Base64
Convertitore di formato delle variabili ambientali
Convertitore di molte unità
Convertitore di numeri romani
Convertitore di proprietà
Convertitore di unità di archiviazione dati
Da CSV a dati
Excel per i dati
Generatore ULID
Normalizzatore di posta elettronica
Testo a Unicode
Testo in binario UTF-8
Torrent a Magnet
Analizzatore SAML
Bcrypt
Calcolatrice CRC
Codificatore/Decodificatore Bech32
Condivisione del segreto di Shamir
Convertitore di certificati SSL
Cripta e decifratura del vault Ansible
Crittografa / decrittografa testo
Crittografia AGE
Crittografia PGP
Crittografia RSA
Crittografia delle stringhe Jasypt
Crittografia file PGP
Firmatario e verificatore RSA/DSA/ECDSA
Generatore HMAC
Generatore JWT
Generatore di CSR
Generatore di certificati X509
Generatore di chiavi PGP
Generatore di coppie di chiavi ECDSA
Generatore di coppie di chiavi Ed25519
Generatore di coppie di chiavi RSA
Hash del testo
Hasher Argon2
Hasher di file
Niceware Bytes in passphrase
Parser JWT
Parser di certificati/chiavi
Paseto/PASERK Local
Paseto/PASERK Pubblico/Privato
Allarme orario
Calcolatore ETA
Calcolatrice Data+Durata
Calcolatrice TTL
Calcolatrice dei giorni
Calcolatrice della durata
Conto alla rovescia
Convertitore data-ora
Convertitore dei numeri delle settimane
Convertitore di fuso orario
Cron/Allarme giorno feriale
Cronometro
Fusione iCal
Generatore ICAL
Parser di file ICAL
Quale giorno?
Calcolatore BMI
Calcolatore del ritmo di corsa
Calcolatrice SLA
Compatibilità della licenza software
Controllo della carta di credito
Convertitore di calendario
Convertitore di valuta
Convertitore maiuscolo RMB
Dizionario online
Linee guida per l'illuminazione IES
Parser e formattatore di numeri di telefono
Ricerca ISO 639
Ricerca Unicode
Ricerca codici paese ISO 3166
Spiega il comando Shell
Validatore Luhn
Validatore di numeri di partita IVA
Validatore e parser IBAN
Validatore e parser ISBN
Convertitore da "docker run" a Docker compose
Convertitore da Docker Compose a Docker Run
Convertitore di formato Docker Compose
Docker Compose nel file .env
Docker Compose per Quadlet
Docker compone per Kubernetes
Esecuzione di Docker su Kubernetes
Esecuzione di Docker su Quadlets
Etichette Docker Pangolin
Generatore RBAC per Kubernetes
Generatore di etichette Dockerfile
Ispezione Docker per esecuzione Docker
Scaricatore di immagini Docker
Traefik Docker Compose Maker
Validatore Docker Compose
Calcolatore di ammortamento
Convertitore di accelerazione
Convertitore di energia alimentare
Convertitore di frequenza
Convertitore di illuminamento
Convertitore di portata volumetrica
Convertitore di potenza
Convertitore di prefissi SI
Convertitore di temperatura
Convertitore di unità angolari
Convertitore di unità di area
Convertitore di unità di energia
Convertitore di unità di forza
Convertitore di unità di lunghezza
Convertitore di unità di massa
Convertitore di unità di pressione
Convertitore di unità di volume
Convertitore di velocità
Prodotti di sicurezza
Analizzatore di e-mail di rimbalzo
Analizzatore di posta elettronica
Analizzatore di report DMARC
Calcolatrice di resistori
Codificatore/decodificatore esadecimale
Console porta seriale
Convertitore GZip/Deflate
Convertitore Middle-Endian
Convertitore ObjectId MongoDB
Convertitore SMART Raw
Convertitore di codifica MIME
Convertitore di numeri in virgola mobile
Decodificatore EMV TLV
Decodificatore URL di condivisione di SharePoint
Decodificatore di Outlook Safelink
Decodificatore di transazioni ETH
Espansore URL brevi
Estrattore ID fiocco di neve
Foglio riassuntivo sul cablaggio RJ45 Cat6
Generatore TCPDump
Generatore URL
Generatore di comandi Nmap
Informazioni sul codice tasto
Lettore di file Parquet
Mascheramento dei dati sensibili
Parser MSG di Outlook
Parser URL
Parser dei cookie
Ricercatore di proprietà LDAP di ActiveDirectory
Rilevatore di tipo di file
Rilevatore/decodificatore di set di caratteri di testo
Tester DNS
Tester HTTPS
Tester di pixel morti
Tester di propagazione DNS
键盘测试器
Convertitore UUID
Generatore UUID
Generatore di NanoID
Generatore di codice OTP
Generatore di codice PIN
Generatore di frase BIP39
Generatore di numeri casuali
Generatore di passphrase
Generatore di password Diceware
Generatore di token
Generatore numeronym
Lanciatore di dadi
Lanciatore di monete
Ruota della fortuna
Selettore di carte
Anteprima SVG
Confronto immagini
Convertitore HEIC
Convertitore ICO/PNG
Convertitore di formati di immagine
Da GIF a MP4
Filigrana
Immagine in SVG (ritratto)
Invertitore di colore dell'immagine
Lettore di qualità EXIF/Metadati/GPS/JPEG dell'immagine
OCRize immagine e PDF
Registratore di telecamera
Ridimensionatore di immagini
Rimuovi EXIF
Rimuovi lo sfondo dell'immagine
Ritaglia immagine
Analizzatore di dimensioni JSON
Array PHP in JSON
CSV in JSON
Codice JSON in PHP
Convertitore JSON to TOML
Convertitore JSON to YAML
Convertitore da JS a JSON
Convertitore da JSON a JS
Convertitore di stringhe JSON
Da Json a Python
Da ObjGen a JSON
Differenza JSON
Editor JSON
Fusione JSON
JSON Flattener/Unflattener
JSON Linter
JSON all'oggetto
JSON in .env
JSON in C#
JSON in MessagePack
JSON in PHP-Array
JSON in SQL DDL
JSON in Schema
JSON in TS
JSON in XML
JSON in dati
JSON in entità Java
JSON per andare
JSON prettify e format
JSON sort master
JSON to CSV
Json Escaper/Unescaper
Minify JSON
Pacchetto messaggi in JSON
Query Json
Tester Jq/JSONPath
tools.json-patch.name
Calcolatore di mance
Calcolatrice binaria
Convertitore di formati matematici
OCR matematico
Valutatore matematico
Visualizzatore di curve trigonometriche/equazioni
Benchmark builder
Calcolatore di percentuale
Calcolatrice del rapporto d'aspetto
Calcolatrice della distanza geografica
Compressore PDF
Concatenatore PDF
Crittografia PDF
Da HTML a PDF
Decifrare e sbloccare PDF
Estrattore di pagine PDF
Estrattore di testo PDF
Pdf Linearizza/FastWeb
Verificatore firme PDF
Generatore di espressioni Cron
ARPA Decoder
Analizzatore di forza della password
Autorizzazione SIP
Calcolatore chmod
Calcolatore dell'intervallo CIDR-IPv4/6
Calcolatore della velocità di trasferimento dati
Calcolatore di affidabilità RAID
Calcolatore di sottoreti IPv4
Calcolatore di sottoreti visuale
Calcolatrice HDD
Calcolatrice RAID
Calcolatrice RAID ZPOOL
Calcolatrice dell'intervallo IPv4/6 per CIDR
Calcolatrice della subnet IPv6
Calcolatrice di esclusione delle subnet IP
Controllo DNSBL
Controllo Whois
Convertitore Punycode
Convertitore di indirizzi IPv4
Convertitore di indirizzi IPv6
Convertitore di indirizzi MAC
Decodificatore X-VR-SpamCause
Elenco di sottoreti IPv4
Espansore di intervallo IPv4
Foglio riassuntivo di ZPool
Formattatore Nginx
Formattatore di comandi della shell
Forza della password Zxcvbn
Generatore Apache LogRotate
Generatore DNS BIMI
Generatore DNS DKIM
Generatore DNS DMARC
Generatore DNS PTR
Generatore DNS SPF
Generatore FStab
Generatore HTAccess
Generatore Htpasswd/htaccess
Generatore Iptables
Generatore Option43
Generatore Rsync
Generatore ULA IPv6
Generatore WPA PSK
Generatore di autenticazione di base
Generatore di comandi Curl
Generatore di comandi UFW
Generatore di comandi di arresto
Generatore di configurazione Wireguard
Generatore di crontab
Generatore di indirizzi MAC
Generatore di porte casuali
HAS Sanitizer
IPv4-6/IPRange/CIDR in IPRange/CIDR/IPMask
Il mio indirizzo IP
Interi in IPv4/IPv6
Linearizzatore di comandi della shell
Numeri di porta
Ping
Posizione geografica IP
Query DNS
Query DNS/RDAP di Cloudflare
Ricerca indirizzo MAC
Scaricatore multi-link
Test Websocket
Tester di porta TCP/UDP
Tester per microfoni
generatore di riga di comando firewalld
tools.restic-command-generator.name
tools.url-redirection-checker.name
Anteprima dello sconto
Conversione da Markdown a DOCX
Conversione da Markdown a HTML
Conversione da Markdown a Testo
Da Epub a Markdown
Da HTML a markdown
Differenza Markdown
Editor di Markdown
Generatore di indice Markdown
Generatore di tabelle Markdown
Incolla come Markdown
Markdown Lorem Ipsum
Markdown Table Prettifier
Markdown per i dati
tools.markdown-format-converter.name
Foglio di riferimento sulla sintassi JSONPath
Foglio di riferimento sulla sintassi XPath
Foglio riassuntivo K8s
Foglio riassuntivo Nano
Foglio riassuntivo VIM
Foglio riassuntivo comune sulle espressioni regolari
Foglio riassuntivo dei comandi dello schermo
Foglio riassuntivo dei selettori CSS
Foglio riassuntivo del comando Tmux
Foglio riassuntivo del comando Zellij
Foglio riassuntivo del comando chmod
Foglio riassuntivo delle espressioni regolari
Foglio riassuntivo di Bash
Foglio riassuntivo di Docker
Foglio riassuntivo di Docker Compose
Foglio riassuntivo di Docker SWARM
Foglio riassuntivo di Dockerfile
Foglio riassuntivo di Jq
Foglio riassuntivo di Markdown
Foglio riassuntivo di Nginx
Foglio riassuntivo di PowerShell
Foglio riassuntivo di Sed
Foglio riassuntivo per i commit semantici Git
Git cheatsheet
CSS/JS Abbellisci e minimizza
Convertitore di citazioni
Convertitore di file HEX
Convertitore di riccioli
Da JSON a TypeScript
Divisore di file
Editor di comandi Cli
Evidenziatore di codice/script
Falsificatore di dati
Generatore GitIgnore
Generatore Mailto
Generatore di attributi Gita
Generatore di creazione di database
Generatore di favicon
Generatore di meta Open Graph
Generatore di parametri SQL
Generatore di script per test di carico K6
Generatore di segreti Django
Generatore di stringhe di connessione al database
Generatore di tabelle di database
Inserimento da Json a SQL
Javascript Prettifier
Javascript Unobfuscator/Unpacker
Json in Protobuf
Offuscatore Javascript
SQL Minifier
SQL prettify e format
Stacktrace più carino
String Escaper
Test API
Tester Picomart
Tester dell'interfaccia utente Swagger
Tester di fuga ANSI
Timer Pomodoro
TOML Linter
TOML to JSON
TOML to YAML
AI Prompt Splitter
Calcolatrice Levenshtein
Codificatore/decodificatore di token GPT
Condivisione di link social
Confronta i caratteri
Controllore I e L
Convertitore di codice Morse
Convertitore di layout di tastiera
Convertitore di liste
Convertitore di maiuscole/minuscole
Convertitore di rune
Da JSON a TOON
Da TOON a JSON
Diagramma della struttura delle cartelle
Differenza di testo
Elenchi Confronta
Esportatore di sirene
Estrarre testo da HTML
File di pacchetto per l'IA
Formattatore Unicode
Generatore di Lorem ipsum
Generatore di citazioni
Generatore di comandi Sed
Generatore di testo ASCII Art
Generatore/Banner di Zalgo
Immagine in ASCII Art
Lettore RSVP
Obfuscator di stringhe
Parole distinte
Selettore di emoji
Selettore di righe casuali
Sostituzione intelligente del testo e interruzione di riga
Statistiche del testo
Stima del token GPT
Tab per passare agli spazi
Tester di espressioni regolari
Testo all'alfabeto NATO
Testo in nomi Unicode
Traduttore di testo
Trova linee duplicate
Unicode a GSM-7
Abbellitore CSS
Abbellitore HTML
Cattura URL
Codici di stato HTTP
Codifica/decodifica stringhe formattate in formato URL
Controllo del contrasto dei colori
Convertitore CSS XPath
Convertitore di colore
Convertitore di pixel REM
Convertitore di unità CSS
Creatore di frammenti di ricerca di testo URL
Editor HTML WYSIWYG
Escape delle entità HTML
Generatore di URL UTM
Generatore di gradienti CSS
Generatore di segnaposto SVG
HTML in XHTML
HTML in dati
Immagine in CSS
Informazioni sul dispositivo
Minificatore HTML
Parser user-agent
Pulitore HTML
Pulitore URL
Ruota dei colori
Slugify string
Tipi MIME
Da ObjGen a HTML
Formattatore XML
Linter XML
Tester XPath
Tester XSLT
XML in JSON
Convertitore YAML to JSON
Fusione YAML
YAML Flattener/Unflattener
YAML prettify e format
YAML to TOML

Foglio riassuntivo di Bash

Comandi comuni di Bash

Bash is the default shell on most Linux systems and the language of most glue scripts. This sheet covers the interactive shortcuts, the syntax you forget between scripts, and the safety flags worth putting at the top of every file.

#!/usr/bin/env bash
set -euo pipefail

⌨️ Keyboard Shortcuts

KeysDoes
Ctrl+A / Ctrl+EJump to the start / end of the line
Ctrl+B / Ctrl+FBack / forward one character
Alt+B / Alt+FBack / forward one word
Ctrl+U / Ctrl+KCut to the start / end of the line
Ctrl+WCut the word before the cursor
Alt+DCut the word after the cursor
Ctrl+YPaste back what you last cut
Ctrl+T / Alt+TSwap the last two characters / words
Alt+.Insert the last argument of the previous command
Ctrl+LClear the screen
Ctrl+RSearch the history backwards
Ctrl+GAbort the history search
Ctrl+CInterrupt the running command
Ctrl+DEnd of input — logs out of an empty prompt
Ctrl+ZSuspend the running command
Ctrl+S / Ctrl+QFreeze / resume terminal output
Alt+U / Alt+LUpper-case / lower-case to the end of the word

🕰 History

# the last few hundred commands
history

# run command number 42
!42

# run the last command again, or the last one starting with 'ssh'
!!
!ssh

# the last argument of the previous command — also Alt+.
!$

# every argument of the previous command
!*

# re-run the last command with a substitution
^old^new

# forget a command you would rather not keep
history -d 42

# do not record commands that start with a space, and drop duplicates
export HISTCONTROL=ignoreboth
export HISTSIZE=10000 HISTFILESIZE=20000

📁 Files & Directories

# list: long, human sizes, hidden files, newest last
ls -lhAtr

# tree view of a directory
tree -L 2

# copy, move, delete
cp -r src/ dest/
mv old new
rm -rf directory

# create nested directories in one go
mkdir -p project/{src,test,docs}

# symbolic and hard links
ln -s /path/to/target linkname
ln target hardlink

# where is a file, and what is it?
find . -name '*.log' -mtime -7
find . -type f -size +100M
locate nginx.conf
which python3
type -a ls
file archive.bin
stat report.pdf

# disk usage: this directory, and the filesystem
du -sh *
du -h --max-depth=1 | sort -h
df -h

# archives
tar czf backup.tar.gz directory/
tar xzf backup.tar.gz
zip -r archive.zip directory/
unzip archive.zip

🔎 Text & Search

# grep: recursive, line numbers, case-insensitive
grep -rni "pattern" .

# only the matching part, or only the file names
grep -o 'v[0-9.]*' file
grep -rl "TODO" src/

# invert, count, context
grep -v "debug" app.log
grep -c "error" app.log
grep -B2 -A2 "exception" app.log

# head, tail, follow
head -20 file
tail -f /var/log/syslog

# columns, sorting, counting
cut -d',' -f1,3 data.csv
sort -u names.txt
sort -k2 -n scores.txt
uniq -c sorted.txt
wc -l file

# the classic: what are the top ten IPs in this log?
awk '{print $1}' access.log | sort | uniq -c | sort -rn | head

# replace across many files
sed -i 's/old/new/g' *.conf

# translate or delete characters
tr 'a-z' 'A-Z' < file
tr -d '\r' < dos.txt > unix.txt

# split a stream: to a file and onward down the pipe
command | tee output.log | grep error

# build command lines from input
find . -name '*.py' | xargs wc -l
find . -name '*.tmp' -print0 | xargs -0 rm

🖧 System & Network

# who and where am I
whoami; hostname; uname -a; uptime

# processes
ps aux | grep nginx
pgrep -a node
top
htop

# memory and load
free -h
vmstat 1 5

# what is listening, and what has this file open
ss -tulpn
lsof -i :8080
lsof /var/log/app.log

# connectivity
ping -c 4 example.com
traceroute example.com
dig example.com +short
ip addr show
curl -I https://example.com

# transfer files
scp file user@host:/path/
rsync -avz --progress src/ user@host:/dest/

# remote shell, with a tunnel
ssh user@host
ssh -L 8080:localhost:80 user@host

# services and logs (systemd)
systemctl status nginx
journalctl -u nginx -f --since "1 hour ago"

📦 Variables

# assignment: no spaces around the =
name="value"

# only for this one command
DEBUG=1 ./script.sh

# export to child processes
export PATH="$HOME/bin:$PATH"

# read input from the user
read -p "Name: " name
read -rs -p "Password: " pass

# command substitution
today=$(date +%F)

# arithmetic
count=$(( count + 1 ))
let "n = 5 * 3"

# read-only and integer variables
declare -r VERSION=1.0
declare -i counter=0
VariableHolds
$0The name of the script
$1 … $9Positional arguments
$#How many arguments were passed
$@All arguments, each one quoted separately
$*All arguments as a single word
$?Exit status of the last command
$$PID of the current shell
$!PID of the last background job
$_Last argument of the previous command
$HOME $USER $PWD $OLDPWDThe usual environment
$RANDOMA random integer
$LINENOThe current line number — handy in traps

🔤 Parameter Expansion

ExpansionResult
${var:-default}default when var is unset or empty
${var:=default}The same, and assigns it
${var:?message}Abort with message when unset — great for required arguments
${var:+value}value only when var is set
${#var}The length of the value
${var:offset:length}A substring
${var#pattern}Strip the shortest match from the start
${var##pattern}Strip the longest match from the start — ${path##*/} is basename
${var%pattern}Strip the shortest match from the end — ${file%.txt} drops the extension
${var%%pattern}Strip the longest match from the end
${var/old/new}Replace the first match
${var//old/new}Replace every match
${var^^} / ${var,,}Upper-case / lower-case the whole value
path="/var/log/app.log"
echo "${path##*/}"    # app.log
echo "${path%/*}"     # /var/log
echo "${path%.log}"   # /var/log/app

📚 Arrays

# indexed arrays
fruits=(apple banana cherry)
fruits[3]="date"

echo "${fruits[1]}"       # banana
echo "${fruits[@]}"       # every element
echo "${#fruits[@]}"      # how many elements
echo "${!fruits[@]}"      # the indexes
echo "${fruits[@]:1:2}"   # a slice

for fruit in "${fruits[@]}"; do
  echo "$fruit"
done

# associative arrays (bash 4+)
declare -A color
color[apple]="red"
color[banana]="yellow"

echo "${color[apple]}"
for key in "${!color[@]}"; do
  echo "$key is ${color[$key]}"
done

🧪 Tests & Conditions

Use [[ ... ]] in bash — it handles empty variables and patterns far better than the old [ ... ].

FilesTrue when
-e fileIt exists
-f fileIt exists and is a regular file
-d fileIt exists and is a directory
-L fileIt is a symbolic link
-s fileIt exists and is not empty
-r -w -xYou can read / write / execute it
-O fileYou own it
f1 -nt f2f1 is newer than f2 (-ot for older)
StringsTrue when
-z "$s"The string is empty
-n "$s"The string is not empty
"$a" == "$b"They are equal (= also works)
"$a" != "$b"They differ
"$a" < "$b"Sorts before, in the current locale
"$s" == pre*Glob match — unquoted right-hand side
"$s" =~ ^re$Regex match, captures land in $BASH_REMATCH
NumbersMeaning
-eqEqual
-neNot equal
-ltLess than
-leLess than or equal
-gtGreater than
-geGreater than or equal
if [[ -f "$config" && -r "$config" ]]; then
  echo "readable"
elif [[ -d "$config" ]]; then
  echo "that is a directory"
else
  echo "missing"
fi

# arithmetic comparison reads more naturally in (( ))
if (( count > 10 )); then echo "plenty"; fi

🔀 Flow Control

# for over a list, a glob, or a range
for name in alice bob; do echo "$name"; done
for f in *.log; do gzip "$f"; done
for i in {1..10}; do echo "$i"; done
for (( i = 0; i < 10; i++ )); do echo "$i"; done

# while and until
while read -r line; do echo "$line"; done < input.txt
until ping -c1 host &>/dev/null; do sleep 5; done

# case
case "$1" in
  start)   echo "starting" ;;
  stop)    echo "stopping" ;;
  restart) echo "restarting" ;;
  *)       echo "usage: $0 {start|stop|restart}"; exit 1 ;;
esac

# select builds a numbered menu
select choice in build test deploy; do
  echo "you picked $choice"
  break
done

# loop control
continue   # skip to the next iteration
break      # leave the loop

🧰 Functions

greet() {
  local name="${1:?name required}"
  local greeting="${2:-Hello}"
  echo "$greeting, $name!"
  return 0
}

greet "World"
greet "World" "Good morning"

# capture the output, and check the status
message=$(greet "World")
if ! greet; then echo "greet failed"; fi

# make a function available to subshells
export -f greet

➡️ Redirection

SyntaxDoes
> fileSend stdout to a file, replacing it
>> fileAppend stdout to a file
2> fileSend stderr to a file
2>&1Send stderr wherever stdout is going
&> fileSend both to a file (bash)
> file 2>&1The portable form of the same
< fileRead stdin from a file
<<EOF … EOFHere-document
<<-EOF … EOFHere-document, leading tabs stripped
<<< "string"Here-string
|Pipe stdout into the next command
|&Pipe stdout and stderr
> /dev/null 2>&1Discard everything
<(command)Process substitution — a command as a file
tee fileWrite to a file and pass the stream on
# a heredoc, expanded
cat <<EOF > config.ini
host=$HOSTNAME
port=8080
EOF

# a heredoc, literal (quoted delimiter)
cat <<'EOF' > script.sh
echo "$HOME is not expanded here"
EOF

# compare the output of two commands without temporary files
diff <(sort a.txt) <(sort b.txt)

⚙️ Jobs & Processes

# run in the background, and list the jobs
long_task &
jobs

# bring back to the foreground, or resume in the background
fg %1
bg %1

# Ctrl+Z suspends the foreground job

# survive logout
nohup ./script.sh > out.log 2>&1 &
disown -h %1

# wait for background jobs
wait
wait $!

# signals
kill 1234
kill -9 1234
kill -TERM %1
pkill -f "node server.js"

# give a command a deadline
timeout 30s ./slow_task.sh

# clean up on exit, whatever happens
trap 'rm -f "$tmpfile"' EXIT
trap 'echo interrupted; exit 130' INT TERM

🛡 Safe Scripting

#!/usr/bin/env bash
# -e  exit on any failing command
# -u  treat unset variables as an error
# -o pipefail  a pipeline fails if any stage fails
set -euo pipefail

# make word splitting predictable
IFS=$'\n\t'

# always quote expansions
cp "$src" "$dest"

# check the syntax without running anything
bash -n script.sh

# trace every command as it runs
bash -x script.sh
set -x; risky_command; set +x

# a more informative trace prefix
export PS4='+ ${BASH_SOURCE}:${LINENO}: '

# report where a script died
trap 'echo "failed at line $LINENO with status $?" >&2' ERR

# and lint it before it reaches anyone else
shellcheck script.sh

⚠️ set -e has surprising corners: it does not fire inside if, &&, || or command substitutions used in assignments. It is a seatbelt, not autopilot — still check what matters explicitly.

🎨 Colours

Escape sequences take the form \033[<style>;<colour>m, and \033[0m resets. \e and \x1B are the same character as \033.

ColourForegroundBrightBackground
Black309040
Red319141
Green329242
Yellow339343
Blue349444
Magenta359545
Cyan369646
White379747
StyleCodeStyleCode
Reset0Underline4
Bold1Blink5
Dim2Reverse7
RED='\033[0;31m'
GREEN='\033[0;32m'
BOLD='\033[1m'
RESET='\033[0m'

echo -e "${GREEN}ok${RESET} — ${RED}${BOLD}failed${RESET}"

# only colourise when stdout is a terminal
if [[ -t 1 ]]; then RED='\033[0;31m'; RESET='\033[0m'; else RED=''; RESET=''; fi

💡 Tips

# aliases and functions belong in ~/.bashrc
alias ll='ls -lhA'
alias gs='git status -sb'
mkcd() { mkdir -p "$1" && cd "$1"; }

# reload the config after editing it
source ~/.bashrc

# brace expansion saves a lot of typing
cp config.yaml{,.bak}
mkdir -p src/{components,utils,tests}

# repeat the previous command as root
sudo !!

# go back to the previous directory
cd -

# run something regardless of the current directory
(cd /tmp && ./task.sh)

# time a command, and keep a transcript of a session
time ./build.sh
script session.log

📚 Resources

  • GNU Bash manual
  • ShellCheck — lints your scripts
  • Bash Pitfalls
  • Google Shell Style Guide
  • explainshell — break down any command line