Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash: syntax error in expression (error token is ...)

Tags:

bash

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
like image 300
dsign Avatar asked Aug 26 '26 16:08

dsign


1 Answers

"${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.

like image 127
Adrian Bartyczak Avatar answered Aug 28 '26 06:08

Adrian Bartyczak



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!