Tutorial by Examples

A newline can be included in a single-string or double-quoted string. Note that backslash-newline does not result in a newline, the line break is ignored. newline1=' ' newline2=" " newline3=$'\n' empty=\ echo "Line${newline1}break" echo "Line${newline2}break" ...
Variable substitutions should only be used inside double quotes. calculation='2 * 3' echo "$calculation" # prints 2 * 3 echo $calculation # prints 2, the list of files in the current directory, and 3 echo "$(($calculation))" # prints 6 Outside of doubl...
All the examples in this paragraph print the line !"#$&'()*;<=>? @[\]^`{|}~ A backslash quotes the next character, i.e. the next character is interpreted literally. The one exception is a newline: backslash-newline expands to the empty string. echo \!\"\#\$\&\'\(\)\*\;\...
The above type handler can be installed into SqlMapper using the AddTypeHandler method. SqlMapper.AddTypeHandler<IHtmlString>(new IHtmlStringTypeHandler()); Type inference allows you to omit the generic type parameter: SqlMapper.AddTypeHandler(new IHtmlStringTypeHandler()); There's als...
The & operator will perform a binary AND, where a bit is copied if it exists in both operands. That means: # 0 & 0 = 0 # 0 & 1 = 0 # 1 & 0 = 0 # 1 & 1 = 1 # 60 = 0b111100 # 30 = 0b011110 60 & 30 # Out: 28 # 28 = 0b11100 bin(60 & 30) # Out: 0b11100
The | operator will perform a binary "or," where a bit is copied if it exists in either operand. That means: # 0 | 0 = 0 # 0 | 1 = 1 # 1 | 0 = 1 # 1 | 1 = 1 # 60 = 0b111100 # 30 = 0b011110 60 | 30 # Out: 62 # 62 = 0b111110 bin(60 | 30) # Out: 0b111110
The ^ operator will perform a binary XOR in which a binary 1 is copied if and only if it is the value of exactly one operand. Another way of stating this is that the result is 1 only if the operands are different. Examples include: # 0 ^ 0 = 0 # 0 ^ 1 = 1 # 1 ^ 0 = 1 # 1 ^ 1 = 0 # 60 = 0b1111...
The << operator will perform a bitwise "left shift," where the left operand's value is moved left by the number of bits given by the right operand. # 2 = 0b10 2 << 2 # Out: 8 # 8 = 0b1000 bin(2 << 2) # Out: 0b1000 Performing a left bit shift of 1 is equivalent ...
The >> operator will perform a bitwise "right shift," where the left operand's value is moved right by the number of bits given by the right operand. # 8 = 0b1000 8 >> 2 # Out: 2 # 2 = 0b10 bin(8 >> 2) # Out: 0b10 Performing a right bit shift of 1 is equivalent...
if [[ $file1 -ef $file2 ]]; then echo "$file1 and $file2 are the same file" fi “Same file” means that modifying one of the files in place affects the other. Two files can be the same even if they have different names, for example if they are hard links, or if they are symbolic links...
if [[ -r $filename ]]; then echo "$filename is a readable file" fi if [[ -w $filename ]]; then echo "$filename is a writable file" fi if [[ -x $filename ]]; then echo "$filename is an executable file" fi These tests take permissions and ownership into a...
Numerical comparisons use the -eq operators and friends if [[ $num1 -eq $num2 ]]; then echo "$num1 == $num2" fi if [[ $num1 -le $num2 ]]; then echo "$num1 <= $num2" fi There are six numeric operators: -eq equal -ne not equal -le less or equal -lt less than ...
String comparison uses the == operator between quoted strings. The != operator negates the comparison. if [[ "$string1" == "$string2" ]]; then echo "\$string1 and \$string2 are identical" fi if [[ "$string1" != "$string2" ]]; then echo &quot...
The -e conditional operator tests whether a file exists (including all file types: directories, etc.). if [[ -e $filename ]]; then echo "$filename exists" fi There are tests for specific file types as well. if [[ -f $filename ]]; then echo "$filename is a regular file&quot...
In helloJohn.sh: #!/bin/bash greet() { local name="$1" echo "Hello, $name" } greet "John Doe" # running above script $ bash helloJohn.sh Hello, John Doe If you don't modify the argument in any way, there is no need to copy it to a local variabl...
Gradients are new image types, added in CSS3. As an image, gradients are set with the background-image property, or the background shorthand. There are two types of gradient functions, linear and radial. Each type has a non-repeating variant and a repeating variant: linear-gradient() repeating-...
Some regular expression flavors allow named capture groups. Instead of by a numerical index you can refer to these groups by name in subsequent code, i.e. in backreferences, in the replace pattern as well as in the following lines of the program. Numerical indexes change as the number or arrangemen...
A description list (or definition list, as it was called before HTML5) can be created with the dl element. It consists of name-value groups, where the name is given in the dt element, and the value is given in the dd element. <dl> <dt>name 1</dt> <dd>value for 1</dd...
You define a map using the keyword map, followed by the types of its keys and its values: // Keys are ints, values are ints. var m1 map[int]int // initialized to nil // Keys are strings, values are ints. var m2 map[string]int // initialized to nil Maps are reference types, and once defined ...
One can declare and initialize a map in a single statement using a composite literal. Using automatic type Short variable declaration: mapIntInt := map[int]int{10: 100, 20: 100, 30: 1000} mapIntString := map[int]string{10: "foo", 20: "bar", 30: "baz"} mapStringInt :...

Page 93 of 1336