On Thu, 6 Mar 2025 15:25:13 GMT, Alexey Semenyuk <asemen...@openjdk.org> wrote:
>> jpackage app laucnher will expand environment variables in .cfg files. >> >> Previously jpackage app launcher only replaced `$APPDIR`, `$BINDIR`, and >> `$ROOTDIR` tokens with the corresponding path values. With this patch, any >> environment variable can be expanded. The syntax is shell-like >> `$ENV_VAR_NAME` or `${ENV_VAR_NAME}`. If `$ENV_VAR_NAME` syntax is used, the >> variable name stops at the first character outside of `[a-zA-Z0-9_]` >> character range. If `${ENV_VAR_NAME}` syntax is used, the variable name >> stops at the first `}` character after `${` substring. E.g: >> | String | Variables | Variable Values | Expanded string | Note | >> | -------- | ------- |------- |------- |------- | >> | <pre>Welcome $USER!</pre> | <pre>USER</pre> | <pre>USER=John</pre> | >> <pre>Welcome John!</pre> || >> | <pre>Welcome $USER!</pre> | <pre>USER</pre> | <pre>not set</pre> | >> <pre>Welcome $USER!</pre> | Unset variables are not expanded. | >> | <pre>Welcome $USER2</pre> | <pre>USER2</pre> | <pre>USER2=John</pre> | >> <pre>Welcome John!</pre> || >> | <pre>Welcome ${USER}2</pre> | <pre>USER</pre> | <pre>USER=John</pre> | >> <pre>Welcome John2!</pre> || >> | <pre>Welcome $USER-2</pre> | <pre>USER</pre> | <pre>USER=John</pre> | >> <pre>Welcome John-2!</pre> || >> | <pre>Welcome ${USER-2}</pre> | <pre>USER-2</pre> | >> <pre>USER-2=John</pre> | <pre>Welcome John!</pre> | `USER-2` is likely to be >> an invalid env variable name, but jpackage launcher is not validating names. >> | >> >> `$` character combination prevents variable expansion: >> | String | Variables | Variable Values | Expanded string | >> | -------- | ------- |------- |------- | >> | <pre>Hello \$A! Bye $B</pre> | B | <pre>B=John</pre> | <pre>Hello $A! Bye >> John</pre> | >> | <pre>Hello \${A}! Bye $B</pre> | B | <pre>B=John</pre> | <pre>Hello ${A}! >> Bye John</pre> | >> >> `\` character combination escapes ``: >> | String | Variables | Variable Values | Expanded string | >> | -------- | ------- |------- |------- | >> | <pre>Hello \\\$A! Bye $B</pre> | A, B | <pre>A=Ana</pre><pre>B=John</pre> >> | <pre>Hello \\Ana! Bye John</pre> | >> >> If `` character is not followed by another `` character or `$` character, it >> is interpreted as a regular character: >> | String | Expanded string | >> | -------- | ------- | >> |<pre>a\\b\\c</pre>|<pre>a\\b\\c</pre>| >> >> >> Expansion is non-recursive: >> | String | Variables | Variable Values | Expanded string | Note | >> | -------- | ------- |------- |------- |------- | >> | <pre>Hello $A!</pre> | A | <pre>A=$B... > > Alexey Semenyuk has updated the pull request incrementally with two > additional commits since the last revision: > > - Merge branch 'JDK-8341641-master' of > https://github.com/alexeysemenyukoracle/jdk into JDK-8341641-master > - Formatting fixed This is true for any shell behavior. It is also true that some shells fail to expand undefined variables if configured accordingly. Bash, for example: bash -c 'FOO=10; echo FOO=$FOO; unset FOO; set -u; echo FOO=$FOO' Output: FOO=10 bash: line 1: FOO: unbound variable .cfg files are not scripts and jpackage app launcher is not an interpreter. Performed string substitution is less variable expansion and more token replacement; if token value is not available, it is not replaced. Regardless of handling undefined variables, users have to deal with the consequences. Say they pass `--java-options -DmyAppData=$HOME/.myData` option to jackage and `HOME` variable happens undefined on a machine where installed app is launched. How would `/.myData` be better than `$HOME/.myData`? At least it is clear something went wrong in the second case. ------------- PR Comment: https://git.openjdk.org/jdk/pull/23923#issuecomment-2704734396