Add stuff

This commit is contained in:
askiiart 2023-08-23 11:54:46 -05:00
parent d34792d34d
commit f08c1ac3f7
4 changed files with 14 additions and 5 deletions

View file

@ -1,4 +1,4 @@
#!/bin/bash #!/usr/bin/env bash
# Exit if there's an error # Exit if there's an error
set -e set -e
# Modify constants as needed # Modify constants as needed

11
random-bash.md Normal file → Executable file
View file

@ -49,9 +49,18 @@ echo "Package manager: ${PM}"
This exits with and error message if it's run as root. This exits with and error message if it's run as root.
```bash ```bash
#!/bin/bash #!/usr/bin/env bash
if [ $(whoami) != "root" ]; then if [ $(whoami) != "root" ]; then
>&2 echo Rerun as non-root user >&2 echo Rerun as non-root user
exit 1 exit 1
fi fi
```
## Output to stderr
```bash
#!/usr/bin/env bash
# Put `>&2` at beginning or end of line to output to stderr
>&2 echo "This goes to stderr"
echo "This goes to stdout"
``` ```

View file

@ -1,5 +1,5 @@
#!/bin/bash #!/usr/bin/env bash
command_exists() { type "$1" &> /dev/null; } type "$1" &> /dev/null; }
if command_exists "apt-get"; then if command_exists "apt-get"; then
PM="apt-get" PM="apt-get"

View file

@ -1,4 +1,4 @@
#!/bin/bash #!/usr/bin/env bash
# Exit if there's an error # Exit if there's an error
set -e set -e
declare -A osInfo; declare -A osInfo;