Links:

#!/bin/bash
set -u -e -o pipefail -o verbose

V="this is a variable"
this_is_function() {
	V="${V} and we added to V"
}

print_v() {
	echo "V: $V"
}

print_v
this_is_function
print_v

cd cygpath $(echo $USERPROFILE)/src
.
alias cdsrc="cd cygpath $(echo $USERPROFILE)/src"

my_func

Built-In Variables:

$0   name of the script

$#   number of parameters to script/function
$@  all parameters to script/function (sees arguments as separate word)
$*    all parameters to script/function (sees arguments as single word)
$n   positional parameters to script/function

$$   PID of the script
$!   PID of the last command executed (and run in the background)
$?   exit status of the last command  (${PIPESTATUS} for pipelined commands)

Note
$*   is rarely the right choice.
$@ handles empty parameter list and white-space within parameters correctly
$@ should usually be quoted like so "$@"

EXIT_STATUS=$?
vagrant halt
if [ "$EXIT_STATUS" != 0]; then
`    exit $EXIT_STATUS
fi

redirect stderr to stdout and append stdout to a file
cmd 2>&1

redirect (via append) both stderr and stdout to to a file:
cmd &>> out.log

Default function arguments:

foo()
{
    default_arg=${1:-default_value} # doesn't include '-'
}


if [ -z "$FOO" ]; then
...
fi

-z : true if empty string (http://linuxcommand.org/man_pages/bash1.html)
Go to index of articles.

Share on