2

I'm trying to execute a bash script and getting the "Unexpected EOF while looking for matching ' " ' error. Not sure where I'm messing up.

The script is designed to insert .md files as entries into a journal program. The journal program uses the following CLI code to insert each .md file: 'dayone2 -d="YYYY-MM-DD TT:TT" new < "filename". So the script extracts the date from the filename itself and runs the program as above.

#!/bin/bash
#
# October 11, 2015 - John Raymonds
#
for file in *.md
do
# do something on "$file"
year="$(echo "$file" | cut -c 13,14,15,16)"
day="$(echo "$file" | cut -c 18,19)"
month="$(echo "$file" | cut -c 21,22)"
theDate=\"$year"-"$month"-"$day" 12:00PM"\"
#The date should end up in this format "2017-01-24 12:00PM"

/usr/local/bin/dayone2 -d="$theDate" new < "$file"

rm "$file"
done

Where is the code wrong?

1

1 Answer 1

1

The quoting on theDate is wrong. It should be:

theDate="${year}-${month}-${day} 12:00PM"

When assigning to a string variable, you're better off with just a single pair of surrounding double-quotes, and using the ${} syntax to disambiguate your variable names.

2
  • The {} isn't needed in this case as the - character would properly end the name of the variable. $year- would be expanded into the value of $year directly followed by a dash.
    – Kusalananda
    Jan 29, 2017 at 21:34
  • @Kusalananda: true, but I wanted to give him an example that was clear as to how to do it so it always works. $year- will work and $year_ won't, and that distinction will be very tough for a beginner to do a web search for.
    – dpw
    Jan 30, 2017 at 22:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .