bash
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
bash [2023/01/17 14:19] – created roger | bash [2024/11/17 12:59] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 3: | Line 3: | ||
Useful Bash code, with no particular order | Useful Bash code, with no particular order | ||
+ | ===== Add safeguards on every script ===== | ||
+ | |||
+ | At the top of the file, always start your scripts with: | ||
+ | |||
+ | <code bash> | ||
+ | set -euo pipefail | ||
+ | </ | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | |||
+ | More info: https:// | ||
+ | |||
+ | ===== Read passwords with feedback on a script ===== | ||
+ | |||
+ | <code bash> | ||
+ | unset password | ||
+ | charcount=0 | ||
+ | prompt=" | ||
+ | while IFS= read -p " | ||
+ | do | ||
+ | if [[ $char == $' | ||
+ | then | ||
+ | break | ||
+ | fi | ||
+ | if [[ $char == $' | ||
+ | if [ $charcount -gt 0 ] ; then | ||
+ | charcount=$((charcount-1)) | ||
+ | prompt=$' | ||
+ | password=" | ||
+ | else | ||
+ | prompt='' | ||
+ | fi | ||
+ | else | ||
+ | charcount=$((charcount+1)) | ||
+ | prompt=' | ||
+ | password+=" | ||
+ | fi | ||
+ | done | ||
+ | </ |
bash.1673965147.txt.gz · Last modified: 2024/11/17 12:59 (external edit)