background preloader

Bash commands

Facebook Twitter

Getopts

Advanced Bash-Scripting Guide. Other Comparison Operators. A binary comparison operator compares two variables or quantities.

Other Comparison Operators

Note that integer and string comparison use a different set of operators. integer comparison -eq is equal to if [ "$a" -eq "$b" ] -ne is not equal to. Manipulating Strings. Extracts substring from $string at $position.

Manipulating Strings

If the $string parameter is "*" or "@", then this extracts the positional parameters, starting at $position. Extracts $length characters of substring from $string at $position. The position and length arguments can be "parameterized," that is, represented as a variable, rather than as a numerical constant. Example 10-2. Generating an 8-character "random" string If the $string parameter is "*" or "@", then this extracts a maximum of $length positional parameters, starting at $position. expr substr $string $position $length Extracts $length characters from $string starting at $position. expr match "$string" '\($substring\)' Extracts $substring at beginning of $string, where $substring is a regular expression. Manipulating Strings. Arithmetic Expansion. Regular expression. The regular expression(?

Regular expression

<=\.) {2,}(? =[A-Z]) matches at least two spaces occurring after period (.) and before an upper case letter as highlighted in the text above. Each character in a regular expression is either understood to be a metacharacter with its special meaning, or a regular character with its literal meaning. Together, they can be used to identify textual material of a given pattern, or process a number of instances of it that can vary from a precise equality to a very general similarity of the pattern. The pattern sequence itself is an expression that is a statement in a language designed specifically to represent prescribed targets in the most concise and flexible way to direct the automation of text processing of general text files, specific textual forms, or of random input strings. History[edit] Regular expressions originated in 1956, when mathematician Stephen Cole Kleene described regular languages using his mathematical notation called regular sets.

Basic concepts[edit] Read Man Page. Read a line from standard input Syntax read [-ers] [-a ] [-p ] [-t ] [-n ] [-d ] [...]

read Man Page

Options -a aname The words are assigned to sequential indices of the array variable aname, starting at 0. All elements are removed from aname before the assignment. Other name arguments are ignored. -d delim The first character of delim is used to terminate the input line, rather than newline. This is a BASH shell builtin. One line is read from the standard input, and the first word is assigned to the first , the second word to the second , and so on, with leftover words and their intervening separators assigned to the last . If there are fewer words read from the standard input than names, the remaining names are assigned empty values. The characters in the value of the IFS variable are used to split the line into words. The backslash character `\' can be used to remove any special meaning for the next character read and for line continuation. Examples #! Related: