ssh -o StrictHostKeyChecking=accept-new will automatically accept the host key without prompting, even for a fresh container. This option was introduced in OpenSSH 7.6 and automatically adds unknown host keys to ~/.ssh/known_hosts without user interaction.
Quick for loop:
1
for i in{1..10};do echo"Run #$i";done
Get the current dir path
BASH_SOURCE vs $0:
BASH_SOURCE is a Bash array that holds the filenames of the scripts in the current “source call stack”.
BASH_SOURCE[0]: the current script file), even if it was sourced.
BASH_SOURCE[1], [2], etc. = the files that sourced it
$0 = the name of the top-level script you invoked (or bash if you’re in an interactive shell), and it does not change when you source another file.
When you run it without absolute path, BASH_SOURCE[0]: does NOT have the absolute path either . When you run it
Example: if main.sh sources lib/X.sh, then inside X.sh:
it tells dirname: stop parsing flags, everything after it is a path
protects you when your file name starts with a - , like -my_script.sh
when do you create a subshell? like “$()”?
$() is called a parentheses group. It runs the grouped commands in a separate process in the current directory
Pipelines cmd1 | cmd2 also creates its own subshell
$(pwd) will give you the path of where you run this command. That is, if you do:
```bash
cd /tmp
/path/to/scripts/main.sh
$pwd will give /tmp
1
2
3
4
5
6
7
- `.` is source. if `dirname` resolves to `.`, it could be executed if you just do `dirname ...`
### Make an argument required
```bash
local run_dir="${1:?run_dir is required}"
A variable can be empty or unset
$(1?my sentence): ? will trigger my sentence if it’s unset. If the first argument is empty, it still wouldn’t
${1:?run_dir is required} is triggered when $1 is either empty or unset