3

This line in a bash file has been working for six months:

SCRATCH_FOLDER_NAME="${SCRATCH_FOLDER_NAME:scratch--folder}"

and today it decided to be no more, with this error:

SCRATCH_FOLDER_NAME: scratch--folder: syntax error in expression (error token is "folder")

What does it mean?

For reference, here is the complete script:

#!/bin/bash

      SHIMMERCAT_SCRATCH_FOLDER_NAME="${SHIMMERCAT_SCRATCH_FOLDER_NAME:shimmercat-scratch--folder}"
REDIS_UNIX_SOCKET="/unpriv/$SHIMMERCAT_SCRATCH_FOLDER_NAME/redis.sock"

if [[ -z ${DONT_RUN_REDIS+x} ]]; then 

    chown shimmercat:shimmercat $SHIMMERCAT_SCRATCH_FOLDER_NAME

    ...
fi
3
  • Maybe try chown shimmercat:shimmercat "$SHIMMERCAT_SCRATCH_FOLDER_NAME" (with the expansion in "")? Which line is the error on? Commented May 24, 2017 at 15:11
  • The error is in line 3, the one that I wrote first in the question. Commented May 24, 2017 at 15:12
  • 1
    I can reproduce the error in both 3.2 and 4.4, when SCRATCH_FOLDER_NAME is set. It's also possible that 4.0 introduced a bug that made it legal, and said bug wasn't fixed until 4.4; I don't have any older installations available to test that theory. Commented May 24, 2017 at 16:03

1 Answer 1

3

"${SCRATCH_FOLDER_NAME:scratch--folder}" is not a correct parameter expansion. Consider the following, where comma is the delimiter:

# Get string before first matching delimeter
${var%%,*}

# Get string before last matching delimeter
${var%,*}

# Get string after first matching delimeter
${var#*,}

# Get string after last matching delimeter
${var##*,}

As for how it worked I am not sure. Here is a good reference for the different types of parameter expansions.

Sign up to request clarification or add additional context in comments.

1 Comment

Yepp, you are totally right. I should have added a "-", like: SHIMMERCAT_SCRATCH_FOLDER_NAME="${SHIMMERCAT_SCRATCH_FOLDER_NAME:-shimmercat-scratch--folder}" . How it was working before, I have no idea :-(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.