More on this book
Kindle Notes & Highlights
by
Jason Cannon
Read between
July 2 - July 4, 2018
Also, some people refer to the exclamation mark as a "bang." So, #! can be spoken as "sharp bang." The term "Shebang" is an inexact contraction of "sharp bang."
Even though this can work just fine under many circumstances, it's best to be explicit and specify the exact interpreter to be used with the script.
Variables are simply storage locations that have a name.
Use the local keyword before the variable name. Only use the local keyword the first time the local variable is used. Note that the local keyword can only be used inside a function. It's a best practice to use local variables inside of your functions. However, you'll find plenty of shell scripts that do not adhere to this recommendation.
Functions are really like shell scripts within a shell script. Just like a shell script, a function has an exit status, sometimes called a return code. This exit status can be explicitly set by using the return statement and following it with the status you would like to return.
The return statement only accepts a number. Only integers between 0 and 255 can be used as an exit status.
To access the exit status of a function, use $? immediately after the function is called.
The special variable $$ represents the PID of the currently running shell script. I use this so if I run the script multiple times on the same day, the PID will be different each time and thus the existing backups will not be overwritten.
The wc utility is used to count the number of lines, words, and bytes.
Sometimes wildcards are referred to as "globs" or "glob patterns". Globbing is the act of expanding a wildcard pattern into the list of matching files and directories.
If a command accepts a file or directory as an argument, you can use a wildcard in the argument to specify a file or set of files. You'll find yourself using wildcards with commands such as ls, rm, cp, mv, and others. The two main wildcards are the asterisk (*) and the question mark (?).
The question mark matches exactly one character. If you want to find all the files that have only one character preceding ".txt", use ?.txt. To match all the two letter files that begin with an "a", use a?. To match all the files that start with an "a," are then followed by exactly one more character, and then ends in ".txt", use a?.txt.
You can use something called a character class to create very specific search patterns. Start with a left bracket then list one or more characters you want to match and then end with a right bracket.
If you want to exclude characters in a match, use an exclamation mark.
[:alpha:] - Matches alphabetic (letters). This matches both lower and uppercase letters.
[:alnum:] - Matches alphanumeric characters. This character class matches alpha and digits. In other words, it matches any uppercase letters, any lowercase letters, or any decimal digits.
[:digit:] - Represents numbers in de...
This highlight has been truncated due to consecutive passage length restrictions.
[:lower:] - Matches lowercase letters [:space:] - Matches whitespace. This means characters such as spaces, tabs, and newline characters....
This highlight has been truncated due to consecutive passage length restrictions.
What if you want to match one of the wildcard characters? Then you would escape that character with a backslash (\). To escape the wildcard, simply place the backslash before the wildcard character.

