Special characters in linux shell scripting

Before jumping into BASH scripting, it is very important to know special characters in BASH. Here is the list of special characters in BASH.
 
# -> This character (hash) is used for marking the comments in shell script
; -> This character (semi-colon) is used to separate 2 BASH commands.
;; -> This is used in select case construct to mark the end of case block.
. -> This character (dot) is used to indicate current directory. If used in regular expressions, it matches exactly one character. The files with names starting with “.” are treated as hidden files.
” ” and ‘ ‘ -> Double quotes are used to preserve the spaces and identify special characters. Single quotes are used to preserve everything as it is. Variable value substitution does not work
/ -> This character (forward slash) is used as path separator. For example – /etc/passwd. This character is also used as division operator in arithmetic operations.
 -> This character (backward slash) is used to escape following character
` -> backquote is used to execute the command and return the result
: -> This character(colon) is used as field separator in /etc/passwd file and in PATH variable
! -> This character (exclamation mark) is used to invoke commands from bash history. This is also used as not equal to operator (!=)
* -> This character (star or asterisk) is used to match anything during filename expansion. This is also used in regular expressions to match zero or more occurrences of preceding character. Additionally this character is also used as multiplication operator.
** -> This set of characters are used as exponentiation operator.
? -> This character is used as condition operator. In regular expressions, it matches o or 1 character.
$ -> This character is used as variable substitution. In regular expressions, it matches end of line.
$*, $@ -> These set of characters are used to access all positional parameters in one go. We can access each argument separately like $0 – script name, $1 – first parameter …and so on.
$? -> This is used to access the exit status of last BASH command.
$$ -> This is used to get the current process id.
= -> This is used during assignment of value to the variable. This is also used to compare 2 strings or integers.
< -> This symbol is used as Input redirection. It is also used as “less than” comparison operator.
> -> This symbol is used as output redirection. It is also used as “greater than” comparison operator.
>> -> This symbol is used as output redirection. Data is appended to the file.
& -> This character is used to run job in the background. For example – “ls &”
– -> This character is used as minus sign in arithmetic operations. It is also used in cd command like “cd -” which takes you to previous working directory.
+ -> This is used as addition operator in arithmetic operations.

Now let use look at some more complex special characters.
 

, -> This character is used for concatenation of strings.

$() -> Used for command substitution. Command inside parenthesis is executed and assigned to variable on left side. for example data=$(ls). This is also used for defining functions. This is also used for declaring array.

{} -> They are used for parameter expansions. They are also used in xargs and find command as well. For example – echo {a..e}  This command will print values a, b,c,d,e

[] -> This is used to access array element. They are also used to define the character classes. They are also used in condition statements. Some of the operators are -eq, -lt, -gt, -a (logical and operator), -o (logical or operator).

((   )) -> Used to do arithmetic operations. Note that you do not need to use $ sign to access the variable values inside parenthesis.

[[ ]] -> This is used in conditional statements. You can use logical and operator (&&), logical or operator (||) and  =~ (regular expression operator).


Web development and Automation testing

solutions delivered!!