Skip to content

Instantly share code, notes, and snippets.

@therealprocyon
Created May 25, 2018 14:00
Show Gist options
  • Save therealprocyon/6851c0c3390621b5125a24f04d265b6e to your computer and use it in GitHub Desktop.
Save therealprocyon/6851c0c3390621b5125a24f04d265b6e to your computer and use it in GitHub Desktop.
part of a shell script of a tutorial in need of refactoring
#!/bin/bash
# Script by CC Oosting (TheRealProcyon) made on 2018-05-25
# Script that was made for a tutorial, which reports the number of files in a dir,
# as well as how many folders (WIP), what the biggest file is (WIP), and more
# checks if a command is given
if [ $# != 1 ]
then
echo "To use this script give in an existing directory"
exit
fi
# check if directory does exist
if [ ! -d $1 ]
then
echo "directory doesn't exist, try again and give a real directory this time"
exit
elif [ -d $1 ]
then
read -p "Directory exists, do you want to list the file amount? [Y/n]" filesamountquestion
read -p "Do you want to list how many dirs there are in this dir? [Y/n]" diramountquestion
read -p "Do you want to list what the biggest file is? [Y/n]" biggestfilequestion
read -p "Do you want to view what the most recently modified file is? [Y/n]" modifiedquestion
read -p "Do you want to list what users own files in this directory? [Y/n]" ownersquestion
case ${filesamountquestion:0:1} in
n|N|m|M|b|B )
# TODO
echo "nah"
;;
* )
# TODO
echo "okay"
;;
esac
case ${diramountquestion:0:1} in
n|N|m|M|b|B )
# TODO
echo "nah"
;;
* )
# TODO
echo "okay"
;;
esac
case ${biggestfilequestion:0:1} in
n|N|m|M|b|B )
# TODO
echo "nah"
;;
* )
# TODO
echo "okay"
;;
esac
case ${modifiedquestion:0:1} in
n|N|m|M|b|B )
# TODO
echo "nah"
;;
* )
# TODO
echo "okay"
;;
esac
case ${ownersquestion:0:1} in
n|N|m|M|b|B )
# TODO
echo "nah"
;;
* )
# TODO
echo "okay"
;;
esac
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment