shell_or_bash_scripts
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| shell_or_bash_scripts [2016/05/25 06:23] – skipidar | shell_or_bash_scripts [2022/10/14 06:01] (current) – [Double-Dash in Shell commands] skipidar | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ===== Shell or Bash Scripts ===== | + | ====== Shell or Bash Scripts |
| |Shebang|Header, | |Shebang|Header, | ||
| - | |Sourcing| < | + | |Sourcing| < |
| + | < | ||
| + | vs Execute in current shell: | ||
| + | < | ||
| - | Guides | + | ===== Guides===== |
| - | |http:// | + | |
| - | |https:// | + | |
| - | |http:// | + | |
| - | |http:// | + | |
| - | == Executing | + | |https:// |
| + | |http:// | ||
| + | |https:// | ||
| + | |http:// | ||
| + | |http:// | ||
| - | Sourcing. | + | ===== Executing or Sourcing the script===== |
| + | |||
| + | Sourcing. | ||
| + | Execute | ||
| < | < | ||
| - | Execute in current shell: | + | Executing. |
| + | Execute in a **NEW** shell - e.g. cd doesn' | ||
| < | < | ||
| - | == declare Function== | + | |
| + | ===== Syntax ===== | ||
| + | |||
| + | ==== declare Function==== | ||
| Returning result is done via **echo** | Returning result is done via **echo** | ||
| Line 53: | Line 63: | ||
| </ | </ | ||
| - | == declare Map == | + | ==== declare Map ==== |
| Big A!!! | Big A!!! | ||
| < | < | ||
| Line 64: | Line 74: | ||
| </ | </ | ||
| - | == iterate array keys == | + | ==== iterate array keys ==== |
| Access via **${!array[@]}** | Access via **${!array[@]}** | ||
| Line 75: | Line 85: | ||
| </ | </ | ||
| - | == dereference an array / map value == | + | ==== dereference an array / map value ==== |
| < | < | ||
| ${ARRAY[2]} | ${ARRAY[2]} | ||
| Line 95: | Line 105: | ||
| </ | </ | ||
| - | == Command Substitution == | + | ==== Command Substitution |
| Command substitution allows the output of a command to replace the command itself. Command substitution occurs when a command is enclosed like this: | Command substitution allows the output of a command to replace the command itself. Command substitution occurs when a command is enclosed like this: | ||
| Line 108: | Line 118: | ||
| `command` | `command` | ||
| </ | </ | ||
| + | |||
| + | |||
| + | ==== Input from command line ==== | ||
| + | If a command expects **a file** as input - one can pass input from STDOUT instead, | ||
| + | without storing the output to a file first by using following syntax | ||
| + | |||
| + | **oc create -f** expects a file here. | ||
| + | |||
| + | < | ||
| + | oc process -f build/ | ||
| + | oc process -f build/ | ||
| + | </ | ||
| + | |||
| + | |||
| + | ==== Double-Dash -- in Shell commands ==== | ||
| + | A double-dash in a shell command signals the end of options and disables further option processing. | ||
| + | https:// | ||
| + | |||
| + | |||
| + | <sxh shell> | ||
| + | # If we use the same approach, we'll receive an error: | ||
| + | # That's because grep treats " | ||
| + | grep " | ||
| + | |||
| + | #works | ||
| + | grep -- --hello data.txt | ||
| + | </ | ||
shell_or_bash_scripts.1464157406.txt.gz · Last modified: (external edit)
