4

I've written a small bash script for work: I'm trying to update a file automatically based on the metadata.

Overall, the script works fine, but anytime I save a new version I get the error:

egrep: parentheses not balanced

If I rewrite the line that begins HOSTEDDATE=, using the exact same syntax, it works again. I suspect it has something to do with the quotation marks which seem to change in appearance (perfectly vertical when first typed, angled after being re-saved as a new version).

Since I'm using plain text in TextEdit, is this a known issue? Is there a workaround that doesn't involve me re-writing the same line over and over again?

The relevant portion of the code is below:

for PIURL in ${ARRAY[*]}
    do
    HOSTEDDATE=`cURL -s ${PIURL} | strings | egrep -o "CreationDate\(D:[0-9]{6}" | egrep -o "[0-9]{6}"`
    FILE=${PIURL##*/}
    NAME=${FILE%.*}

    #find local file and pull date
    LOCALDATE=`ls $NAME* | egrep -o "[0-9]{6}"`

        if [[ ${HOSTEDDATE} > ${LOCALDATE} ]]; then
        #move old file to "ARCHIVED"
        mv $NAME* ARCHIVED/

        #download PI file with required name
        cURL -L -o ${NAME}_${HOSTEDDATE}.pdf $PIURL

        #send e-mail with 
        mail -s "${NAME} has a new PI" [email protected] <<< "${NAME}_${DATE} has been uploaded to Pulse"
        fi
done
4
  • 1
    I don't understand what you're asking. Commented Dec 17, 2017 at 19:24
  • 2
    Likely to do with encoding – this may help: Quotes problem in Mavericks (or TextEdit) Commented Dec 17, 2017 at 19:41
  • 2
    The answer (above) here doesn't specify this, but smart quotes can be disabled at application-level via TextEdit > Preferences > Smart quotes (checkbox) as well (or restricted to rich text format). Commented Dec 17, 2017 at 19:43
  • See my answer below for a comprehensive list of options to disable this feature. Commented Dec 17, 2017 at 20:02

2 Answers 2

3

This is a side-effect of the Smart quotes feature in MacOS. To disable, apply:

TextEdit > Preferences > Smart quotes (uncheck)

enter image description here

Alternatively, to restrict Smart quotes to rich-text documents only, apply:

TextEdit > Preferences > Smart quotes and dashes in rich text documents only (check)

enter image description here

Lastly, if you want to disable Smart quotes system-wide, refer to: Quotes problem in Mavericks (or TextEdit)

2

That sounds like your text editor changes the standard ASCII quotes to some fancier quotes. The problem with them is that the shell doesn't consider anything but the ASCII quotes as quotes, so the behavior changes.

E.g. normal quotes:

$ echo "foo\(bar"
foo\(bar

vs. fancy quotes:

$ echo “foo\(bar”
“foo(bar”

In the first case, the quotes protect the backslash, and had that been egrep, the backslash would protect the left parenthesis. In the second case, the shell doesn't see any quotes, so it handles the backslash, which is gone when the command sees it, and egrep will take it as the start of a grouping construct.

The solution is to fix the editor to produce ASCII quotes, or to use one that doesn't insist on changing the quotes.

1
  • 1
    Looks like you’re correct about the quotation marks not being ASCII — Travis provided some further clarification about this being an issue starting with Mavericks and how to circumvent it. Commented Dec 17, 2017 at 20:06

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.