myhelp:bash
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| myhelp:bash [2023/05/03 12:20] – ulrich | myhelp:bash [2024/03/07 12:12] (current) – ulrich | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== | + | # Read a file per line |
| - | < | + | |
| + | ``` | ||
| + | # while read line; do echo " | ||
| + | ``` | ||
| + | |||
| + | # Upper to Lower | ||
| - | ====== Upper to Lower ====== | ||
| Is pretty easy done | Is pretty easy done | ||
| - | < | + | |
| + | ``` | ||
| + | # cat / | ||
| + | ``` | ||
| or | or | ||
| - | < | ||
| - | ====== | + | ``` |
| + | # echo " | ||
| + | ``` | ||
| + | |||
| + | # SED Examples | ||
| Delete a line with a string in it. For example old ssh-keys: | Delete a line with a string in it. For example old ssh-keys: | ||
| - | < | ||
| - | ====== | + | ``` |
| + | # sed -i "/ | ||
| + | ``` | ||
| + | |||
| + | # Calculate | ||
| You can use the expr | You can use the expr | ||
| - | < | + | |
| + | ``` | ||
| + | # expr 1 + 2 | ||
| + | ``` | ||
| and you will get 3 as result. | and you will get 3 as result. | ||
| Also some more fancy stuff is possible. For example in a for-loop: | Also some more fancy stuff is possible. For example in a for-loop: | ||
| - | < | ||
| - | ====== | + | ``` |
| + | for i in {1..9}; do echo " | ||
| + | ``` | ||
| + | |||
| + | # Bash redirection | ||
| stdout to file | stdout to file | ||
| - | < | + | |
| + | ``` | ||
| + | # command > file.txt | ||
| + | ``` | ||
| stderr to file | stderr to file | ||
| - | < | + | |
| + | ``` | ||
| + | # command 2> /dev/null | ||
| + | ``` | ||
| stdout AND stderr to file | stdout AND stderr to file | ||
| - | < | + | |
| + | ``` | ||
| + | # command &> file.txt | ||
| + | ``` | ||
| stdout to file AND stderr to file | stdout to file AND stderr to file | ||
| - | < | + | |
| + | ``` | ||
| + | # command > file.txt 2> /dev/null | ||
| + | ``` | ||
| stdout to stderr | stdout to stderr | ||
| - | < | + | |
| + | ``` | ||
| + | # command 1>&2 | ||
| + | ``` | ||
| stderr to stdout | stderr to stdout | ||
| - | < | ||
| - | {{tag>[Good2Know bash]}} | + | ``` |
| + | # command 2>&1 | ||
| + | ``` | ||
myhelp/bash.1683116428.txt.gz · Last modified: by ulrich
