0

properties.ini

PROFILES="--spring.profiles.active=local"
PROPERTIES="--spring.config.import=file:./properties/"

script.sh

#!/bin/bash
# Read the INI file and set its values as variables
source /app/backend/properties.ini

/usr/bin/java -jar /app/backend/backend-api.jar $PROFILES $PROPERTIES

I have a bash script to run jar files.

Additionally, a properties.ini file exists to dynamically control environment variables.

Then I load this file with the source command and use it in the bash script.

But if you look at the code above,

PROFILES="--spring.profiles.active=local"

A problem occurs in this part.

If you hard-code this environment variable, there will be no problem, but if you load it through source, it will not work and an error will occur when running the jar.

If you try to output through echo, you can also check that it appears correctly.

While trying to fix this, I accidentally added "space" at the end and the problem went away.

Modified code:

properties.ini

PROFILES="--spring.profiles.active=local "  # << space
PROPERTIES="--spring.config.import=file:./properties/"

Other environment variables work correctly even without these spaces.

If you look at the command executed after that, that's a bit strange too. A dot is added after each environment variable.

root        4687       1 99 04:08 pts/2    00:00:21 /usr/bin/java -jar /app/backend/backend-api.jar --spring.profiles.active=local . --spring.config.import=file:./properties/.
  1. Unlike other environment variables, why does the profile environment variable require a final space?

  2. Why is the command executed like this appended with a dot?

  • 2
    Was your INI file edited on Windows? What is the output of file properties.ini? – muru Oct 11 '23 at 04:39
  • 1
    Are you a genius? you're right. The file was backed up in Windows, so it was copied from Windows.

    I checked again and found that the ini was set to "executable file (chmod +x)".

    After deleting and recreating it as a document file, all problems were resolved.

    – 남혁준 Oct 11 '23 at 04:50
  • 1
    So somewhere in your backup or transfer process, the line-endings of the file are changed to Windows ones. Linux uses LF, Windows uses CRLF. The extra character there is the reason for your problem, and this comes up every now and then on this site with various mysterious effects. – muru Oct 11 '23 at 06:09
  • 1
    This is the perfect answer. After checking a little more, it seemed to have nothing to do with the presence of an executable file, but rather a problem with newline characters. (The problem disappeared when I changed CRLF to LF.)

    Your words confirmed my thoughts. Thank you.

    – 남혁준 Oct 11 '23 at 06:15

0 Answers0