- python -m SimpleHTTPServer #serve current directory at http://localhost:8000
- https://stackoverflow.com/questions/793858/how-to-mkdir-only-if-a-dir-does-not-already-exist?rq=1 create directory .
- https://stackoverflow.com/questions/8748831/when-do-we-need-curly-braces-in-variables-using-bash Curly braces.
- http://www.tldp.org/LDP/abs/abs-guide.pdf 900 page guide
- https://linuxacademy.com/blog/linux/conditions-in-bash-scripting-if-statements/ file conditions etc.
- https://opensource.com/article/17/6/bash-parameter-expansion parameter expansion
if conditionals Edit
t's very simple. You just have to understand , [] and (()) as completely different beasts.
[ expression ] is just an invocation of a program [ (just a different name for test) and takes the expression as arguments, just like for all command calls in bash. That means, you must use whitespace between arguments, especially after [ and before ], and keywords and special characters have to be escaped or quoted, and variables are expanded in the usual way.
Within the expression, -gt, -lt and related are used for numerical comparison, while >, < and the sort, are for string comparisons. Think of [ as nothing to do with bash, just calling a command that evaluates expressions and returns 0 (true) or non-zero (false), as all programs do.
Boolean operators && and || can't be used in there, because they get interpreted by bash and not passed to test as arguments. -a and -o are used instead. But you can always do [ test1 ] && [ test2 ] || [ test3 ], which are 3 test invocations, combined by bash's usual boolean operators (that is, if first fails, the second is skipped).
Note that bash still comes with its own implementation of [ (builtin), but that doesn't change the way it's treated syntactically.
[[ ]] and (( )) are not builtin replacements for commands, but parts of a special syntax, so different rules apply. See man page for details on how variable names are wildcards are treated there. Boolean operators && and || have the usual meaning.
The [[ ]] one is string-centered: all comparsions are for strings (but are more "modern", locale-aware than in [, although test could be platform-dependent). It handles also file tests, regex and so on.
The (( )) is for arithmetic expressions. Variable names don't require $ there, and you can mostly just write mathematical expressions in there - that of course includes comparisons (which are numerical). Comparisons in this case are no different from any other arithmetic expression, true is 1, false is 0, and you can write stuff like (( x=y*(z>4) )). If used in a conditional expression, nonzero is true and zero is false. You can also capture the result as $(( )).
[[ ]] string conditionals, pattern matching and file tests (( )) arithmetic expressions and conditionals [ ] test command: handles both, special nonstandard syntax for boolean operators and comparison operators
Unix stackexchange Edit
- http://mywiki.wooledge.org/BashFAQ/055 , http://wiki.bash-hackers.org/scripting/copydescriptor redirecting 2>&1
- http://www.gnu.org/software/bash/manual/bashref.html redirecting input, output piping section 3.6
- http://sourcemage.org/Sorcery/Book shell style guide, a clone of Linuxfromscratch.com
- http://www.codebind.com/linux-tutorials/bash-shell-scripting-statement-fi-else-fi-elif-else-fi/ if then else
- https://ubuntuforums.org/showthread.php?t=664657 store functions in separate file.
- http://redsymbol.net/articles/bash-exit-traps/ exit traps
https://www.youtube.com/watch?v=xC5NKqXmdUo Record All Screen Output to File - BASH -Linux 4,678 views