Ben Chuanlong Du's Blog

It is never too late to learn.

Bash Equivalent of the ifmain Pattern in Python

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

#!/usr/bin/env bash

function install_icon.usage() {
    cat << EOF
NAME
    /scripts/sys/install_icon.sh - Download and install icon to /usr/local/bin/.
SYNTAX 
    /scripts/sys/install_icon.sh [-h]
EOF
}

function install_icon …

Get OS and Architecture Information in Shell

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

Command Description
uname -a The full info of the machine.
uname The type of OS, e.g., Linux, Darwin, etc.
uname -m The architecture of the machine, e.g., x86_64, etc …

Extended Globbing in Bash

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

Enable Extended Globbing

shopt -s extglob

Or you can run bash with the option -O extglob.

/bin/bash -O extglob -c "your command to run"

Set Shell to be Bash with …

Operators in Different Programming Languages

Python Bash C/C++ Java Julia
and and -a && && &&
or or -o || || ||
not not ! ! ! !
bit and & & & & &
bit or | | | | |
bit not ~ ~ ~ ~ ~
bit xor ^ ^ ^ ^ ^
vector and
vector or
vector not
equals == -eq == == ==
not equal != -ne != != !=
greater than > -gt > > >
less than < -lt < < <
greater than or equal to >= -ge >= >= >=
less than or equal to …