Shell Shell scripts automatically removing "{" and "}" from passed in parameter

Hello,

I have a /bin/sh question.

I have a script names script.sh and it takes one parameter. The script looks like this...

Code:
#!/bin/sh

JAVA_EXECUTABLE=java
if [ -n "$JAVA_HOME" ]
then
  JAVA_EXECUTABLE=$JAVA_HOME/bin/java
fi

BASEDIR=$(dirname "$0")
"$JAVA_EXECUTABLE" -jar "${BASEDIR}"/application-jar-with-dependencies.jar "$@"

The issue is that when I execute the script like this...

Code:
# ./script.sh foo{bar}

My Java application is actually passed "foobar" NOT "foo{bar}"...

The "{" and "}" character are being removed.

Any ideas?
 
It's not the script that's swallowing them, it's the shell. Remember that the shell parses the command line before executing it.

# ./script.sh 'foo{bar}'
 
No swallowing happening. Your shell performs brace expansion, it would seem.
Nitpick: Given that "swallowing" is never a correct technical term, but commonly used to describe the side effect typically caused by expansions you're not aware of, there's not really a contradiction here 🥳
 
Back
Top