I am just wondering what, if any, more elegant ways might exist to write a script to accomplish the task that the script below accomplishes. The script works, so I don't need it to be debugged, but I want to learn more. Other commands to be used, other ways of structuring it, etc. I have taken it through shellcheck.
Yesterday I decided to try my hand at a shell script that would create and open a file to take notes for each of my classes in the folder designated for notes from that class. It was pretty satisfying to do; I started with basically no knowledge and over the course of an hour or two I went from a script that would prompt me to enter the class and the desired file title (read Class read Title if [[ $Class = "X]] then touch /path/"$Title".docx
etc) to something that would just create the file in the right place based on the time/date the command is invoked, since the title is always today's date anyhow.
Again, it works. I just know that there must be more ways to skin this cat and I was wondering what those might be. The version below has been revised once after input from some good samaritans.
Also, FWIW, this is running on OS X Sierra.
#!/bin/bash
read date hour day month <<< $(date +"%-d %-H %a %B")
if [[ $hour -lt 11 && $day = "Tue" ]] || [[ $hour -lt 11 && $day = "Thu" ]]; then
dir="/path/to/first"
elif [[ $hour -gt 12 && $hour -lt 15 && $day = "Tue" ]] || [[ $hour -gt 12 && $hour -lt 15 && $day = "Thu" ]]; then
dir="path/to/second"
elif [[ $hour -ge 16 && $hour -le 17 && $day = "Wed" ]]; then
dir="/path/to/third/"
else
echo "I am of no use to you right now"
exit 1
fi
file="$dir/$month $date".docx
touch "$file"
open "$file"
killall Terminal