1779505678
This commit is contained in:
@@ -1,4 +0,0 @@
|
|||||||
run command and display error or success
|
|
||||||
```bash
|
|
||||||
<command>; ret=$? && if [ $ret -ne 0 ]; then echo -e "\n\033[0;31mERRROR! Code: $ret\033[0m"; else echo -e "\033[0;32mOK!\033[0m"; fi
|
|
||||||
```
|
|
||||||
@@ -1,5 +1,56 @@
|
|||||||
# Quick and Dirty Methods (Bash)
|
# Quick and Dirty Methods (Bash)
|
||||||
|
|
||||||
|
colors
|
||||||
|
```bash
|
||||||
|
# Define color variables
|
||||||
|
PINK='\e[35m'
|
||||||
|
BRIGHT_PINK='\e[95m'
|
||||||
|
RED='\033[0;31m'
|
||||||
|
YELLOW='\033[1;33m'
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
RESET='\033[0m' # No Color (RESET)
|
||||||
|
# usage echo -e "$PINKpinktext here$RESET"
|
||||||
|
```
|
||||||
|
|
||||||
show every set variale and its value (one liner)
|
show every set variale and its value (one liner)
|
||||||
```bash
|
```bash
|
||||||
for v in $(compgen -v); do echo "$v:$$v"; done
|
for v in $(compgen -v); do echo "$v:$$v"; done
|
||||||
|
```
|
||||||
|
|
||||||
|
run command and display error or success
|
||||||
|
```bash
|
||||||
|
<command>; ret=$? && if [ $ret -ne 0 ]; then echo -e "\n\033[0;31mERRROR! Code: $ret\033[0m"; else echo -e "\033[0;32mOK!\033[0m"; fi
|
||||||
|
```
|
||||||
|
|
||||||
|
# Function to Display succ/err based on error code
|
||||||
|
```bash
|
||||||
|
checkcode () {
|
||||||
|
if [ -z "$1" ]; then
|
||||||
|
echo -e "\n\e[31mERROR!\033[0m chkcode missing return code paramater\n"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
retcode=$1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $retcode -ne 0 ]; then
|
||||||
|
echo -e "\t\e[31mERROR!\033[0m Response Code: $retcode"
|
||||||
|
else
|
||||||
|
echo -e "\t\e[1;32mOK!\e[0m"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Test a list of commands if they are present
|
||||||
|
```bash
|
||||||
|
cmds_to_check=(sha256sum sha1sum md5sum openssl scrypt)
|
||||||
|
for cmd in ${cmds_to_check[@]}; do
|
||||||
|
if command -v $cmd &>/dev/null; then
|
||||||
|
# echo -e "\033[0;32mOK!\033[0m $cmd is present"
|
||||||
|
continue
|
||||||
|
else
|
||||||
|
echo -e "\n\n\033[0;31mERROR!\033[0m $cmd not found! please intall! Exiting!\n\n" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
echo -e "\033[0;32mOK!\033[0m All Needed Commands Available!"
|
||||||
```
|
```
|
||||||
Reference in New Issue
Block a user