Tutorial by Examples

A readonly list of the options bash is supplied on startup to control its behaviour: ~> $ echo $SHELLOPTS braceexpand:emacs:hashall:histexpand:history:interactive-comments:monitor
When the bash command is executed a new shell is opened. The $SHLVL environment variable holds the number of shell levels the current shell is running on top of. In a new terminal window, executing the following command will produce different results based on the Linux distribution in use. echo $S...
A read only variable that stores the users' ID number: ~> $ echo $UID 12345
Positional parameters passed to the script from either the command line or a function: #!/bin/bash # $n is the n'th positional parameter echo "$1" echo "$2" echo "$3" The output of the above is: ~> $ ./testscript.sh firstarg secondarg thirdarg firstarg sec...

$#

To get the number of command line arguments or positional parameters - type: #!/bin/bash echo "$#" When run with three arguments the example above will result with the output: ~> $ ./testscript.sh firstarg secondarg thirdarg 3

$*

Will return all of the positional parameters in a single string. testscript.sh: #!/bin/bash echo "$*" Run the script with several arguments: ./testscript.sh firstarg secondarg thirdarg Output: firstarg secondarg thirdarg

$!

The Process ID (pid) of the last job run in the background: ~> $ ls & testfile1 testfile2 [1]+ Done ls ~> $ echo $! 21715

$_

Outputs the last field from the last command executed, useful to get something to pass onwards to another command: ~> $ ls *.sh;echo $_ testscript1.sh testscript2.sh testscript2.sh It gives the script path if used before any other commands: test.sh: #!/bin/bash echo "$_" ...

$?

The exit status of the last executed function or command. Usually 0 will mean OK anything else will indicate a failure: ~> $ ls *.blah;echo $? ls: cannot access *.blah: No such file or directory 2 ~> $ ls;echo $? testfile1 testfile2 0

$$

The Process ID (pid) of the current process: ~> $ echo $$ 13246

$@

"$@" expands to all of the command line arguments as separate words. It is different from "$*", which expands to all of the arguments as a single word. "$@" is especially useful for looping through arguments and handling arguments with spaces. Consider we are in a scr...
LINQ provides a built-in function for checking the equality of two IEnumerables, and that function can be used on arrays. The SequenceEqual function will return true if the arrays have the same length and the values in corresponding indices are equal, and false otherwise. int[] arr1 = { 3, 5, 7 };...
Consider this example function to check if a host is up: is_alive() { ping -c1 "$1" &> /dev/null } This function sends a single ping to the host specified by the first function parameter. The output and error output of ping are both redirected to /dev/null, so the functi...
Decorator is one of structural design patterns. It is used to add, remove or change behaviour of object. This document will teach you how to use Decorator DP properly. Let me explain the idea of it to you on a simple example. Imagine you're now in Starbobs, famous coffee company. You can place an o...
Comments in Sass vs. Scss are largely similar, except when multi-lines are concerned. SASS multi-lines are indentation-sensitive, while SCSS relies on comment terminators. Single-Line Comment style.scss // Just this line will be commented! h1 { color: red; } style.sass // Exactly the same ...
ssh -p 21 [email protected] <<EOF echo 'printing pwd' echo "\$(pwd)" ls -a find '*.txt' EOF $ is escaped because we do not want it to be expanded by the current shell i.e $(pwd) is to be executed on the remote shell. Another way: ssh -p 21 [email protected] <...
sudo -s <<EOF a='var' echo 'Running serveral commands with sudo' mktemp -d echo "\$a" EOF $a needs to be escaped to prevent it to be expanded by the current shell Or sudo -s <<'EOF' a='var' echo 'Running serveral commands with sudo' mktemp -d e...
Detailed instructions on getting google-bigquery set up or installed.
IRB means "Interactive Ruby Shell", letting us execute ruby expressions from the standart input. To start, type irb into your shell. You can write anything in Ruby, from simple expressions: $ irb 2.1.4 :001 > 2+2 => 4 to complex cases like methods: 2.1.4 :001> def method ...
Inside your layout, add a Login button with the following code: <com.twitter.sdk.android.core.identity.TwitterLoginButton android:id="@+id/twitter_login_button" android:layout_width="wrap_content" android:layout_height="wrap_content" and...

Page 654 of 1336