| Python | Bash | C/C++ | Java | Julia | |
|---|---|---|---|---|---|
| and | and | -a | && | && | && |
| or | or | -o | || | || | || |
| not | not | ! | ! | ! | ! |
| bit and | & | & | & | & | & |
| bit or | | | | | | | | | | |
| bit not | ~ | ~ | ~ | ~ | ~ |
| bit xor | ^ | ^ | ^ | ^ | ^ |
| vector and | |||||
| vector or | |||||
| vector not | |||||
| equals | == | -eq | == | == | == |
| not equal | != | -ne | != | != | != |
| greater than | > | -gt | > | > | > |
| less than | < | -lt | < | < | < |
| greater than or equal to | >= | -ge | >= | >= | >= |
| less than or equal to … |
Programming in Shell
String¶
Regular Expression Comparison¶
https://stackoverflow.com/questions/229551/how-to-check-if-a-string-contains-a-substring-in-bash
Bash Programming¶
- case ... esac is different from switch(){} in C/C++. You do not have to return/exit manually after each branch.
not condition
if [ ! -d "$1" ]; then
fi
Shell Programing Trick¶
Generate 00, 01, ..., to 25.
for i in {00..25}; do echo $i; doneor
seq -f %02g 0 25
Shell Scripting¶
Environment Variables in Shell
export¶
A new child process forked from a parent process does not inherit parent's variables by default. The export command marks an environment variable to be exported with any newly forked child processes and thus it allows a child process to inherit all marked variables.
unset¶
Bash Programming
Environment Variables¶
export
unset
Tips and Traps¶
explainshell.com is a great place for learning shell.
Bash-it/bash-it is a great community driven Bash framework.
It is suggested that you avoid writing complicated Bash scripts. IPython is a much better alternative.
Do NOT use
;to delimit paths passed to a shell command because;
Shell in Docker
Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!
Configure the Shell for the RUN Command
https://docs.docker.com/engine/reference/builder/#shell
Configure the Default Shell for Terminals in Docker Containers
Just set the SHELL environment variable in …