pure-bash-bible/manuscript/chapter0.txt

116 lines
6.6 KiB
Plaintext

# Table of Contents
<!-- vim-markdown-toc GFM -->
* [Strings](#strings)
* [Trim leading and trailing white-space from string](#trim-leading-and-trailing-white-space-from-string)
* [Trim all white-space from string and truncate spaces](#trim-all-white-space-from-string-and-truncate-spaces)
* [Use regex on a string](#use-regex-on-a-string)
* [Split a string on a delimiter](#split-a-string-on-a-delimiter)
* [Change a string to lowercase](#change-a-string-to-lowercase)
* [Change a string to uppercase](#change-a-string-to-uppercase)
* [Trim quotes from a string](#trim-quotes-from-a-string)
* [Strip all instances of pattern from string](#strip-all-instances-of-pattern-from-string)
* [Strip first occurrence of pattern from string](#strip-first-occurrence-of-pattern-from-string)
* [Strip pattern from start of string](#strip-pattern-from-start-of-string)
* [Strip pattern from end of string](#strip-pattern-from-end-of-string)
* [Check if string contains a sub-string](#check-if-string-contains-a-sub-string)
* [Check if string starts with sub-string](#check-if-string-starts-with-sub-string)
* [Check if string ends with sub-string](#check-if-string-ends-with-sub-string)
* [Arrays](#arrays)
* [Reverse an array](#reverse-an-array)
* [Remove duplicate array elements](#remove-duplicate-array-elements)
* [Random array element](#random-array-element)
* [Cycle through an array](#cycle-through-an-array)
* [Toggle between two values](#toggle-between-two-values)
* [Loops](#loops)
* [Loop over a range of numbers](#loop-over-a-range-of-numbers)
* [Loop over a variable range of numbers](#loop-over-a-variable-range-of-numbers)
* [Loop over an array](#loop-over-an-array)
* [Loop over an array with an index](#loop-over-an-array-with-an-index)
* [Loop over the contents of a file](#loop-over-the-contents-of-a-file)
* [Loop over files and directories](#loop-over-files-and-directories)
* [File handling](#file-handling)
* [Read a file to a string](#read-a-file-to-a-string)
* [Read a file to an array (*by line*)](#read-a-file-to-an-array-by-line)
* [Get the first N lines of a file](#get-the-first-n-lines-of-a-file)
* [Get the last N lines of a file](#get-the-last-n-lines-of-a-file)
* [Get the number of lines in a file](#get-the-number-of-lines-in-a-file)
* [Count files or directories in directory](#count-files-or-directories-in-directory)
* [Create an empty file](#create-an-empty-file)
* [Extract lines between two markers](#extract-lines-between-two-markers)
* [File Paths](#file-paths)
* [Get the directory name of a file path](#get-the-directory-name-of-a-file-path)
* [Get the base-name of a file path](#get-the-base-name-of-a-file-path)
* [Variables](#variables)
* [Assign and access a variable using a variable](#assign-and-access-a-variable-using-a-variable)
* [Escape Sequences](#escape-sequences)
* [Text Colors](#text-colors)
* [Text Attributes](#text-attributes)
* [Cursor Movement](#cursor-movement)
* [Erasing Text](#erasing-text)
* [Parameter Expansion](#parameter-expansion)
* [Indirection](#indirection)
* [Replacement](#replacement)
* [Length](#length)
* [Expansion](#expansion)
* [Case Modification](#case-modification)
* [Default Value](#default-value)
* [Brace Expansion](#brace-expansion)
* [Ranges](#ranges)
* [String Lists](#string-lists)
* [Arithmetic](#arithmetic)
* [Simpler syntax to set variables](#simpler-syntax-to-set-variables)
* [Ternary tests](#ternary-tests)
* [Traps](#traps)
* [Do something on script exit](#do-something-on-script-exit)
* [Ignore terminal interrupt (CTRL+C, SIGINT)](#ignore-terminal-interrupt-ctrlc-sigint)
* [React to window resize.](#react-to-window-resize)
* [Do something before every command.](#do-something-before-every-command)
* [Do something when a shell function or a sourced file finishes executing](#do-something-when-a-shell-function-or-a-sourced-file-finishes-executing)
* [Performance](#performance)
* [Disable Unicode](#disable-unicode)
* [Obsolete Syntax](#obsolete-syntax)
* [Shebang](#shebang)
* [Command Substitution](#command-substitution)
* [Function Declaration](#function-declaration)
* [Internal Variables](#internal-variables)
* [Get the location to the `bash` binary](#get-the-location-to-the-bash-binary)
* [Get the version of the current running `bash` process](#get-the-version-of-the-current-running-bash-process)
* [Open the user's preferred text editor](#open-the-users-preferred-text-editor)
* [Get the name of the current function](#get-the-name-of-the-current-function)
* [Get the host-name of the system](#get-the-host-name-of-the-system)
* [Get the architecture of the Operating System](#get-the-architecture-of-the-operating-system)
* [Get the name of the Operating System / Kernel](#get-the-name-of-the-operating-system--kernel)
* [Get the current working directory](#get-the-current-working-directory)
* [Get the number of seconds the script has been running](#get-the-number-of-seconds-the-script-has-been-running)
* [Get a pseudorandom integer](#get-a-pseudorandom-integer)
* [Information about the terminal](#information-about-the-terminal)
* [Get the terminal size in lines and columns (*from a script*)](#get-the-terminal-size-in-lines-and-columns-from-a-script)
* [Get the terminal size in pixels](#get-the-terminal-size-in-pixels)
* [Get the current cursor position](#get-the-current-cursor-position)
* [Conversion](#conversion)
* [Convert a hex color to RGB](#convert-a-hex-color-to-rgb)
* [Convert an RGB color to hex](#convert-an-rgb-color-to-hex)
* [Code Golf](#code-golf)
* [Shorter `for` loop syntax](#shorter-for-loop-syntax)
* [Shorter infinite loops](#shorter-infinite-loops)
* [Shorter function declaration](#shorter-function-declaration)
* [Shorter `if` syntax](#shorter-if-syntax)
* [Simpler `case` statement to set variable](#simpler-case-statement-to-set-variable)
* [Other](#other)
* [Use `read` as an alternative to the `sleep` command](#use-read-as-an-alternative-to-the-sleep-command)
* [Check if a program is in the user's PATH](#check-if-a-program-is-in-the-users-path)
* [Get the current date using `strftime`](#get-the-current-date-using-strftime)
* [Generate a UUID V4](#generate-a-uuid-v4)
* [Progress bars](#progress-bars)
* [Get the list of functions from your script](#get-the-list-of-functions-from-your-script)
* [Bypass shell aliases](#bypass-shell-aliases)
* [Bypass shell functions](#bypass-shell-functions)
* [Afterword](#afterword)
<!-- vim-markdown-toc -->
<!-- CHAPTER END -->