Try Documentalist,
my app that offers fast, offline access to 190+ programmer API docs.
Links:
- http://wiki.bash-hackers.org/syntax/quoting : notes on quoting
- https://devhints.io/bash
- http://robertmuth.blogspot.com/2012/08/better-bash-scripting-in-15-minutes.html
- https://news.ycombinator.com/item?id=7595499
- https://google.github.io/styleguide/shell.xml, https://www.reddit.com/r/programming/comments/8jm85w/googles_bash_style_guide/
- https://github.com/anordal/shellharden/blob/master/how_to_do_things_safely_in_bash.md, https://www.reddit.com/r/programming/comments/8jke5b/safe_ways_to_do_things_in_bash/
#!/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
[email protected] 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.
[email protected] handles empty parameter list and white-space within parameters correctly
[email protected] should usually be quoted like so "[email protected]"
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)