Main Body
7 Quick Reference Guide
Common Notations
Here are some commonly used but easy-to-forget notations and syntax.
Notation | Typical usage with mini-example | Where to get more info |
---|---|---|
single quotes (‘) | Creates literal string protecting special characters.
grep 'Al Shaji' namelist |
Shell Variables |
double quotes (“) | Like single quotes but interprets $, \ for variables.
echo "Price: $value" |
|
$(cmd) | Command substitution. Runs cmd and substitutes output of cmd at position of call.
today=$(date) |
man bash
|
set braces { } | Formal variable specification; substrings.
echo ${alpha:3:5} 3 is offset (zero-based) and 5 is length |
|
double parentheses (( )) | Arithmetic expression.
a=$(( $a + 1 )) |
man bash |
left square bracket [ | Synonym for test command.
if [ $op = MR ] Closing right bracket is needed. |
man test |
[[ string =~ regex ]] | Checks to see if regular expression (regex) is contained in string
Example [[ importing =~ port ]] will return TRUE Can be used with variables, too. Example [[ $title =~ $word ]] returns TRUE if $word is contained within $title |
man bash |
Character classes in regular expressions
[abc] |
Square brackets represent a single character pattern. Thus,
r[aou]n matches ran, ron, or run. [Pp]olish matches Polish or polish |
man regex.7
|
FAQs
Q1a: How do make my script executable?
Q1b: I’m getting an error message, “-bash: ./myscript: Permission denied”
A1: You need to issue the chmod command, either:
-
chmod 700 myscript
-
chmod u+x myscript