Created
December 18, 2020 13:41
-
-
Save alst74/4d70a37e883b2096378d5be11efd419b to your computer and use it in GitHub Desktop.
Bash loops and tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
FILENAME=$1 | |
for FILENAME in "$@"; do | |
if ! [ -e "$FILENAME" ]; then | |
echo "File not found ($FILENAME). Skipping..." | |
elif [ -d "$FILENAME" ]; then | |
ORIG_IFS=$IFS | |
IFS=$(echo -en "\n\b") | |
for F in $(find "$FILENAME" -type f); do | |
ls -lah $F | |
done | |
IFS=$ORIG_IFS | |
elif [ -f "$FILENAME" ]; then | |
ls -lah "$FILENAME" | |
else | |
echo "Invalid file ($FILENAME). Skipping..." | |
fi | |
done | |
if ! [ -e "$CONFIG_DIRECTORY" ]; then | |
if ! mkdir -p "$CONFIG_DIRECTORY" &> /dev/null; then | |
echo "Config directory $CONFIG_DIRECTORY does not exist and could not be created." | |
exit 1 | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment