Skip to content

Instantly share code, notes, and snippets.

@alst74
Created December 18, 2020 13:41
Show Gist options
  • Save alst74/4d70a37e883b2096378d5be11efd419b to your computer and use it in GitHub Desktop.
Save alst74/4d70a37e883b2096378d5be11efd419b to your computer and use it in GitHub Desktop.
Bash loops and tests
#!/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