Simple todo bash script

This file is written for the Day planner and the Tasks plugin in obsidian. This script allows me to quickly add a todo task in the appropriate place.

This is written with the assistance of ChatGPT. Here is my prompt:

Prompt

Please write a bash script that does the following:

  1. takes three arguments: The first argument will be put in the variable [tag], the second argument will be the variable [task_name], the third variable will be the variable [due_date].
  2. get today's year, month and date, and make them number only. So if today is 2023, January 22nd, change that into 20230122 and but that in a variable "date"
  3. Search in path [predefined path]/"Day Planners" for a file that contains "date". put the path of the file in variable "file_path" Error handle this step
  4. put the string "- [ ] [tag] [task_name] 📅 [due_date]" at the end of the file

Here's the actual bash script:

#!/bin/bash
tag=$1
tag="#$tag"
task_name=$2
due_date=$3
root_path="<pre-defined path>"
date=$(date +%Y%m%d) #get today's date in the format of YYYYMMDD
path="$root_path/Day Planners/" #predefined path
file_path=$(find "$path" -type f -name *$date* -print0 | xargs -0 echo) #search for file containing the date
if [ -z "$file_path" ]; then #if file path is empty, display error message
  echo "Error: No file found with the date $date"
else
  echo "- [ ] $tag $task_name 📅 $due_date" >> "$file_path" #append the task string to the end of the file
  echo "Task added"
fi