Substitution Operators are substituted by what they stand for.
Imagine you got that little command line from bash_tips that outputs your IP-address:
duffman:~ # ifconfig eth1 | sed -rn 's/^.*inet addr:([^ ]+).*$/\1/p' 192.168.0.6
Now, you want your IP address stored into a variable, say, you want to substitute the commandline by its output and store it to a variable. Use the operator $() to do this:
duffman:~ # ip=$(ifconfig eth1 | sed -rn 's/^.*inet addr:([^ ]+).*$/\1/p' ) duffman:~ # echo $ip 192.168.0.6 duffman:~ #
The operator $() executes the statement that is within its paranthesis and substitutes itself with the output of that statement. Backticks (``) do the same, but they are not cascadable.
$((content)) is substituted by the arithmetic evaluation of content.
The operator * is substituted by all files in your current folder, e.g.
behaves the same as
ls file1 file2 file3...
Evaluating Operators deliver a return code in dependance from their content. Example:
[[ $a = $b ]]
delivers 0 if $a is $b, else, it delivers a non-null return code.
A redirect or redirection is the mechanism with that output is sent to a different destination than its default. You can redirect the output of commands or your own input.
$ echo foo > bar
sends foo to bar rather than the screen. bar is an ordinary file, but can also be a device.
$ echo foo >> bar
will append the string "foo" to the ordinary file "bar".
$ echo foo > bar
is short for
$ echo foo 1> bar
which means that the stream 1, stdout will be redirected to bar.
You can redirect output from any command:
$ ls 1> myfiles
duffman:~ # ls a /bin/ls: a: No such file or directory duffman:~ # ls a 1>/dev/null /bin/ls: a: No such file or directory duffman:~ #
The redirection does not work here - obviously, the error message ("No such file or directory") has been sent to another stream than stdout. It has been sent to stderr (Standard Error Stream). The stream's numbers are as follows:
So, the following redirects the error message to /dev/null:
duffman:~ # ls a 2>/dev/null duffman:~ #
In the following, there is an example of a command (ls text a) that outputs one line to stderr and one to stdout. You can find there how to unite both streams (stdin and stdout).
duffman:~ # ls text a /bin/ls: a: No such file or directory text duffman:~ # ls text a 2>/dev/null text duffman:~ # ls text a 1>/dev/null /bin/ls: a: No such file or directory duffman:~ # ls text a 2>&1 | wc -l 2 duffman:~ #
The redirection "2>&1" makes that the error messages are sent to stdout as well. You can count the number of lines produces with a pipe and wc. Now the following example sends all output from stdout and stderr to a file:
duffman:~ # ls text a >text 2>&1 duffman:~ # cat text /bin/ls: a: No such file or directory text duffman:~ #
The command cat > file << EOF will redirect the stdin-stream to the ordinary file "file". It will not stop sending the input there till the input is "EOF". So, the following example will create a file "text" with 3 lines:
duffman:~ # cat >text<<END > my first line > my second line > my last line before END > END duffman:~ #
tweedleburg:~ # sleep 60 &  14655 tweedleburg:~ # jobs + Running sleep 60 & tweedleburg:~ # echo $! 14655 tweedleburg:~ # kill $! tweedleburg:~ # jobs + Terminated sleep 60
The & operator allows to start a program in the background, e.g.
Will allow you to continue executing commands while firefox is started and run in parallel.