Tutorial by Examples: c

$ a='I am a string with spaces' $ [ $a = $a ] || echo "didn't match" bash: [: too many arguments didn't match [ $a = $a ] was interpreted as [ I am a string with spaces = I am a string with spaces ]. [ is the test command for which I am a string with spaces is not a single argument...
while IFS= read -r line;do echo "**$line**" done < <(ping google.com) or with a pipe: ping google.com | while IFS= read -r line;do echo "**$line**" done
Classes have instance variable (dependencies), on which they call methods. Example taken from http://www.jamesshore.com/Blog/Dependency-Injection-Demystified.html for reference public class Example { private DatabaseThingie myDatabase; public Example() { myDatabase = new DatabaseTh...
Let's assume that the field separator is : while IFS= read -d : -r field || [ -n "$field" ];do echo "**$field**" done < <(ping google.com) Or with a pipe: ping google.com | while IFS= read -d : -r field || [ -n "$field" ];do echo "**$field**&q...
pat='[^0-9]+([0-9]+)' s='I am a string with some digits 1024' [[ $s =~ $pat ]] # $pat must be unquoted echo "${BASH_REMATCH[0]}" echo "${BASH_REMATCH[1]}" Output: I am a string with some digits 1024 1024 Instead of assigning the regex to a variable ($pat) we could als...
a='I am a simple string with digits 1234' pat='(.*) ([0-9]+)' [[ "$a" =~ $pat ]] echo "${BASH_REMATCH[0]}" echo "${BASH_REMATCH[1]}" echo "${BASH_REMATCH[2]}" Output: I am a simple string with digits 1234 I am a simple string with digits 1234
This counts the number of lines in a big file with wc -l while simultaneously compressing it with gzip. Both run concurrently. tee >(wc -l >&2) < bigfile | gzip > bigfile.gz Normally tee writes its input to one or more files (and stdout). We can write to commands instead of fil...
Class Car ... ' Parameterless Constructor Public Sub Class_Initialize() distances_ = Array(0) End Sub ' Default initialization method that can be invoked without ' explicitly using the method name. Public Default Function Init(wheels) wheels_ = ...
Quotes will be output as-is: echo "Some Text" "Some Text" Comment tokens are ignored: echo Hello World REM this is not a comment because it is being echoed! Hello World REM this is not a comment because it is being echoed! However, echo will still output var...
SET TEST=0 IF %TEST% == 0 ( echo TEST FAILED ) ELSE IF %TEST% == 1 ( echo TEST PASSED ) ELSE ( echo TEST INVALID )
FIND command can scan large files line-by-line to find a certain string. It doesn't support wildcards in the search string. find /i "Completed" "%userprofile%\Downloads\*.log" >> %targetdir%\tested.log TYPE scan2.txt | FIND "Failed" /c && echo Scan fai...
The following script shows more advanced split file technique, where FOR function loops through a list of files in a directory, and each file content is piped to FINDSTR that looks for a string containing substring var preceded by undefined number of spaces and superseded by any extra text. Once fou...
Basic Syntax Julia's array comprehensions use the following syntax: [expression for element = iterable] Note that as with for loops, all of =, in, and ∈ are accepted for the comprehension. This is roughly equivalent to creating an empty array and using a for loop to push! items to it. result ...
Configuring the Primary Server Requirements: Replication User for replication activities Directory to store the WAL archives Create Replication user createuser -U postgres replication -P -c 5 --replication + option -P will prompt you for new password + option -c is for max...
When we’re first starting our work, we have to decide if this is a separate area of work we’re working on, or is this part of an existing line of work. If it’s existing, we can work off of that branch. If it’s new, we’ll start a new branch. Our workflow then is: hg branch MyNewFeature work wo...
Enumeration types can also be declared without giving them a name: enum { buffersize = 256, }; static unsigned char buffer [buffersize] = { 0 }; This enables us to define compile time constants of type int that can as in this example be used as array length.
Julia uses the standard mathematical meanings of arithmetic operations when applied to matrices. Sometimes, elementwise operations are desired instead. These are marked with a full stop (.) preceding the operator to be done elementwise. (Note that elementwise operations are often not as efficient as...
Wrapper script is a script that wraps another script or command to provide extra functionalities or just to make something less tedious. For example, the actual egrep in new GNU/Linux system is being replaced by a wrapper script named egrep. This is how it looks: #!/bin/sh exec grep -E "$@&q...
You can have functions in the PS1 variable, just make sure to single quote it or use escape for special chars: gitPS1(){ gitps1=$(git branch 2>/dev/null | grep '*') gitps1="${gitps1:+ (${gitps1/#\* /})}" echo "$gitps1" } PS1='\u@\h:\w$(gitPS1)$ ' It will...
This is how the author sets their personal PS1 variable: gitPS1(){ gitps1=$(git branch 2>/dev/null | grep '*') gitps1="${gitps1:+ (${gitps1/#\* /})}" echo "$gitps1" } #Please use the below function if you are a mac user gitPS1ForMac(){ git branch 2> ...

Page 472 of 826