Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the "eval" error due to empty lines in the INI file #44

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

milanbalazs
Copy link
Contributor

Why:

If there is empty trailing line in the INI file you can get the following error:

eval: line 64: syntax error near unexpected token `}'

Solution:

  • My change removes the empty lines from INI file.

My test INI file:

# This config file is used for testing

[SERVER]
user            = user
pws             = password

My test code:

#!/bin/bash -e

SCRIPT_FULL_PATH=$(readlink -f "${BASH_SOURCE[0]:-${0}}")
SCRIPT_DIR_PATH="${SCRIPT_FULL_PATH%/*}"

source "${SCRIPT_DIR_PATH}/bash_ini_parser.sh"

cfg_parser "${SCRIPT_DIR_PATH}/configs/servers.ini"

echo "DONE"

Test run without my change (With an extra echo):

 >>> ./test.sh 

}
cfg_section_SERVER () {
cfg_unset SERVER
user=( user )
pws=( password )
}
/home/milanbalazs/scripts/bash_ini_parser.sh: eval: line 65: syntax error near unexpected token `}'

Test run with my change (With an extra echo):

>>> ./test.sh 
cfg_section_SERVER () {
cfg_unset SERVER
user=( user )
pws=( password )
}
DONE

Conclusion:

  • As you can see above my change solves the wrong and unnecessary } character beginning of the structure of eval function.

If there is empty trailing line in the INI file you can get the following error:

eval: line 64: syntax error near unexpected token `}'

My change removes the empty lines from INI file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant