how to set JVM property line.separator to newline from bash





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







1















I want to set JVM System property line.separator to a single newline on Windows (it's already a single newline by default everywhere else).



This scala script is used to display the effective line.separator property:



#!/usr/bin/env scala
val bytes = sys.props("line.separator").map { _.toInt }.mkString(" ")
printf("line.separator bytes: %sn",bytes)


On a windows JVM, it normally prints the following:



line.separator bytes: 13 10


Briefly, I'm looking for a way to launch my test script so that it prints the following output:



line.separator bytes: 10


I can achive this with the following JAVA_OPTS setting:



export JAVA_OPTS=-Dline.separator=$'n'


but only if I also modify the standard scala script by surrounding $JAVA_OPTS with double quotes. Here's the section near the end of the scala script verbatim (i.e., WITHOUT the needed modification):



execCommand 
"${JAVACMD:=java}"
$JAVA_OPTS
"${java_args[@]}"
"${classpath_args[@]}"
-Dscala.home="$SCALA_HOME"
$OVERRIDE_USEJAVACP
$WINDOWS_OPT
scala.tools.nsc.MainGenericRunner "$@"


With these two modifications, the test script above prints the following:



$ reportLineSeparator.sc
line.separator bytes: 10


Adding quotes to JAVA_OPTS is not a viable option, however, since that would prevent it from being unset, or from specifying multiple settings.



So the requirement seems to be to somehow arrange for the unquoted JAVA_OPTS to be correctly handled without losing the encoded newline.



I'm starting to suspect that there is solution, although I'm hopeful that someone will prove me wrong.



Update: it seems that if a bash array is used instead of JAVA_OPTS, that would provide a solution, since it could be quoted in the scala script. In other words, replace the unquoted $JAVA_OPTS above with this:



"${JAVA_OPTS_ARR[@]}" 


I was pleasantly surprised that it also doesn't cause problems when JAVA_OPTS_ARR is undefined.



However, this isn't a viable solution because it's not possible to export bash arrays (see Exporting an array in bash script)



Follow-up: after further thinking about this problem, I concluded that interpolation isn't the issue. The quotes are needed to contain the variable as a single command line argument. So that raises the question as to whether the Internal Field Separator (IFS) could be used to keep the entire line.separator definition as a single command line argument without quotes.



Okay, it seems that if I add the following to the scala launch script, the line.separator setting seems to take effect:



IFS=' '


I can then append to JAVA_OPTS like this and get the desired behavior:



JAVA_OPTS="$JAVA_OPTS "-Dline.separator=$'n'


The IFS setting has to occur prior to where the unquoted $JAVA_OPTS occurs.



Update: this invocation, suggested by @som-snytt seems to work:



scala -J-Dline.separator=$'n' -nc lineSeparatorBytes.sc









share|improve this question

























  • scala -J-Dline.separator=$'r'$'n' seems to work because of java_args.

    – som-snytt
    Nov 18 '18 at 3:59











  • doesn't work for me in a cygwin bash shell, although it's somewhat more challenging to determine whether it worked because you're setting to the default setting for Windows JVM.

    – philwalk
    Nov 28 '18 at 19:45




















1















I want to set JVM System property line.separator to a single newline on Windows (it's already a single newline by default everywhere else).



This scala script is used to display the effective line.separator property:



#!/usr/bin/env scala
val bytes = sys.props("line.separator").map { _.toInt }.mkString(" ")
printf("line.separator bytes: %sn",bytes)


On a windows JVM, it normally prints the following:



line.separator bytes: 13 10


Briefly, I'm looking for a way to launch my test script so that it prints the following output:



line.separator bytes: 10


I can achive this with the following JAVA_OPTS setting:



export JAVA_OPTS=-Dline.separator=$'n'


but only if I also modify the standard scala script by surrounding $JAVA_OPTS with double quotes. Here's the section near the end of the scala script verbatim (i.e., WITHOUT the needed modification):



execCommand 
"${JAVACMD:=java}"
$JAVA_OPTS
"${java_args[@]}"
"${classpath_args[@]}"
-Dscala.home="$SCALA_HOME"
$OVERRIDE_USEJAVACP
$WINDOWS_OPT
scala.tools.nsc.MainGenericRunner "$@"


With these two modifications, the test script above prints the following:



$ reportLineSeparator.sc
line.separator bytes: 10


Adding quotes to JAVA_OPTS is not a viable option, however, since that would prevent it from being unset, or from specifying multiple settings.



So the requirement seems to be to somehow arrange for the unquoted JAVA_OPTS to be correctly handled without losing the encoded newline.



I'm starting to suspect that there is solution, although I'm hopeful that someone will prove me wrong.



Update: it seems that if a bash array is used instead of JAVA_OPTS, that would provide a solution, since it could be quoted in the scala script. In other words, replace the unquoted $JAVA_OPTS above with this:



"${JAVA_OPTS_ARR[@]}" 


I was pleasantly surprised that it also doesn't cause problems when JAVA_OPTS_ARR is undefined.



However, this isn't a viable solution because it's not possible to export bash arrays (see Exporting an array in bash script)



Follow-up: after further thinking about this problem, I concluded that interpolation isn't the issue. The quotes are needed to contain the variable as a single command line argument. So that raises the question as to whether the Internal Field Separator (IFS) could be used to keep the entire line.separator definition as a single command line argument without quotes.



Okay, it seems that if I add the following to the scala launch script, the line.separator setting seems to take effect:



IFS=' '


I can then append to JAVA_OPTS like this and get the desired behavior:



JAVA_OPTS="$JAVA_OPTS "-Dline.separator=$'n'


The IFS setting has to occur prior to where the unquoted $JAVA_OPTS occurs.



Update: this invocation, suggested by @som-snytt seems to work:



scala -J-Dline.separator=$'n' -nc lineSeparatorBytes.sc









share|improve this question

























  • scala -J-Dline.separator=$'r'$'n' seems to work because of java_args.

    – som-snytt
    Nov 18 '18 at 3:59











  • doesn't work for me in a cygwin bash shell, although it's somewhat more challenging to determine whether it worked because you're setting to the default setting for Windows JVM.

    – philwalk
    Nov 28 '18 at 19:45
















1












1








1








I want to set JVM System property line.separator to a single newline on Windows (it's already a single newline by default everywhere else).



This scala script is used to display the effective line.separator property:



#!/usr/bin/env scala
val bytes = sys.props("line.separator").map { _.toInt }.mkString(" ")
printf("line.separator bytes: %sn",bytes)


On a windows JVM, it normally prints the following:



line.separator bytes: 13 10


Briefly, I'm looking for a way to launch my test script so that it prints the following output:



line.separator bytes: 10


I can achive this with the following JAVA_OPTS setting:



export JAVA_OPTS=-Dline.separator=$'n'


but only if I also modify the standard scala script by surrounding $JAVA_OPTS with double quotes. Here's the section near the end of the scala script verbatim (i.e., WITHOUT the needed modification):



execCommand 
"${JAVACMD:=java}"
$JAVA_OPTS
"${java_args[@]}"
"${classpath_args[@]}"
-Dscala.home="$SCALA_HOME"
$OVERRIDE_USEJAVACP
$WINDOWS_OPT
scala.tools.nsc.MainGenericRunner "$@"


With these two modifications, the test script above prints the following:



$ reportLineSeparator.sc
line.separator bytes: 10


Adding quotes to JAVA_OPTS is not a viable option, however, since that would prevent it from being unset, or from specifying multiple settings.



So the requirement seems to be to somehow arrange for the unquoted JAVA_OPTS to be correctly handled without losing the encoded newline.



I'm starting to suspect that there is solution, although I'm hopeful that someone will prove me wrong.



Update: it seems that if a bash array is used instead of JAVA_OPTS, that would provide a solution, since it could be quoted in the scala script. In other words, replace the unquoted $JAVA_OPTS above with this:



"${JAVA_OPTS_ARR[@]}" 


I was pleasantly surprised that it also doesn't cause problems when JAVA_OPTS_ARR is undefined.



However, this isn't a viable solution because it's not possible to export bash arrays (see Exporting an array in bash script)



Follow-up: after further thinking about this problem, I concluded that interpolation isn't the issue. The quotes are needed to contain the variable as a single command line argument. So that raises the question as to whether the Internal Field Separator (IFS) could be used to keep the entire line.separator definition as a single command line argument without quotes.



Okay, it seems that if I add the following to the scala launch script, the line.separator setting seems to take effect:



IFS=' '


I can then append to JAVA_OPTS like this and get the desired behavior:



JAVA_OPTS="$JAVA_OPTS "-Dline.separator=$'n'


The IFS setting has to occur prior to where the unquoted $JAVA_OPTS occurs.



Update: this invocation, suggested by @som-snytt seems to work:



scala -J-Dline.separator=$'n' -nc lineSeparatorBytes.sc









share|improve this question
















I want to set JVM System property line.separator to a single newline on Windows (it's already a single newline by default everywhere else).



This scala script is used to display the effective line.separator property:



#!/usr/bin/env scala
val bytes = sys.props("line.separator").map { _.toInt }.mkString(" ")
printf("line.separator bytes: %sn",bytes)


On a windows JVM, it normally prints the following:



line.separator bytes: 13 10


Briefly, I'm looking for a way to launch my test script so that it prints the following output:



line.separator bytes: 10


I can achive this with the following JAVA_OPTS setting:



export JAVA_OPTS=-Dline.separator=$'n'


but only if I also modify the standard scala script by surrounding $JAVA_OPTS with double quotes. Here's the section near the end of the scala script verbatim (i.e., WITHOUT the needed modification):



execCommand 
"${JAVACMD:=java}"
$JAVA_OPTS
"${java_args[@]}"
"${classpath_args[@]}"
-Dscala.home="$SCALA_HOME"
$OVERRIDE_USEJAVACP
$WINDOWS_OPT
scala.tools.nsc.MainGenericRunner "$@"


With these two modifications, the test script above prints the following:



$ reportLineSeparator.sc
line.separator bytes: 10


Adding quotes to JAVA_OPTS is not a viable option, however, since that would prevent it from being unset, or from specifying multiple settings.



So the requirement seems to be to somehow arrange for the unquoted JAVA_OPTS to be correctly handled without losing the encoded newline.



I'm starting to suspect that there is solution, although I'm hopeful that someone will prove me wrong.



Update: it seems that if a bash array is used instead of JAVA_OPTS, that would provide a solution, since it could be quoted in the scala script. In other words, replace the unquoted $JAVA_OPTS above with this:



"${JAVA_OPTS_ARR[@]}" 


I was pleasantly surprised that it also doesn't cause problems when JAVA_OPTS_ARR is undefined.



However, this isn't a viable solution because it's not possible to export bash arrays (see Exporting an array in bash script)



Follow-up: after further thinking about this problem, I concluded that interpolation isn't the issue. The quotes are needed to contain the variable as a single command line argument. So that raises the question as to whether the Internal Field Separator (IFS) could be used to keep the entire line.separator definition as a single command line argument without quotes.



Okay, it seems that if I add the following to the scala launch script, the line.separator setting seems to take effect:



IFS=' '


I can then append to JAVA_OPTS like this and get the desired behavior:



JAVA_OPTS="$JAVA_OPTS "-Dline.separator=$'n'


The IFS setting has to occur prior to where the unquoted $JAVA_OPTS occurs.



Update: this invocation, suggested by @som-snytt seems to work:



scala -J-Dline.separator=$'n' -nc lineSeparatorBytes.sc






bash scala newline interpolation jvm-arguments






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 7 '18 at 14:13







philwalk

















asked Nov 16 '18 at 18:41









philwalkphilwalk

4881512




4881512













  • scala -J-Dline.separator=$'r'$'n' seems to work because of java_args.

    – som-snytt
    Nov 18 '18 at 3:59











  • doesn't work for me in a cygwin bash shell, although it's somewhat more challenging to determine whether it worked because you're setting to the default setting for Windows JVM.

    – philwalk
    Nov 28 '18 at 19:45





















  • scala -J-Dline.separator=$'r'$'n' seems to work because of java_args.

    – som-snytt
    Nov 18 '18 at 3:59











  • doesn't work for me in a cygwin bash shell, although it's somewhat more challenging to determine whether it worked because you're setting to the default setting for Windows JVM.

    – philwalk
    Nov 28 '18 at 19:45



















scala -J-Dline.separator=$'r'$'n' seems to work because of java_args.

– som-snytt
Nov 18 '18 at 3:59





scala -J-Dline.separator=$'r'$'n' seems to work because of java_args.

– som-snytt
Nov 18 '18 at 3:59













doesn't work for me in a cygwin bash shell, although it's somewhat more challenging to determine whether it worked because you're setting to the default setting for Windows JVM.

– philwalk
Nov 28 '18 at 19:45







doesn't work for me in a cygwin bash shell, although it's somewhat more challenging to determine whether it worked because you're setting to the default setting for Windows JVM.

– philwalk
Nov 28 '18 at 19:45














1 Answer
1






active

oldest

votes


















1














JAVA_OPTS is an ancient convention but not a standard. It was introduced to the scala script in 2007 and overtaken by -J in 2010.



I think the best option (so to speak) is scala -J-Dline.separator=$'r'$'n'.



There is a PR now for your suggestion, which seems safe, except it also keeps tab for the case:



JAVA_OPTS="-Xmx256m <tab> -Xss1m".



Shell quoting is so much fun! I try to refresh my scarred memory every five years or so.



Edit: the answer was that passing the line.separator to Scala's background compile server broke. There are several issues with the compile server (which can be invoked with fsc for the "fast" scala compiler), which is now deprecated. The solution here, as always, is to use the -nc to request "no compile daemon" for your script. Compilation of the script takes a second longer, but you save hours or days of debugging.






share|improve this answer


























  • your best option seems to get me into the REPL, but if I pass a script path, if fails with 'Usage: fsc <options> ...'. Are you testing in a cygwin bash environment?

    – philwalk
    Nov 19 '18 at 19:40











  • Your -nc invocation suggestion works for me, if you write it up I'll mark your response as the solution.

    – philwalk
    Dec 7 '18 at 11:56











  • OK cool, that's weird enough to deserve an answer on SO. Personally, I gave up on fsc a long time ago and always use -nc (which is now a deprecated option because it is the default behavior).

    – som-snytt
    Dec 7 '18 at 13:25












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53343645%2fhow-to-set-jvm-property-line-separator-to-newline-from-bash%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














JAVA_OPTS is an ancient convention but not a standard. It was introduced to the scala script in 2007 and overtaken by -J in 2010.



I think the best option (so to speak) is scala -J-Dline.separator=$'r'$'n'.



There is a PR now for your suggestion, which seems safe, except it also keeps tab for the case:



JAVA_OPTS="-Xmx256m <tab> -Xss1m".



Shell quoting is so much fun! I try to refresh my scarred memory every five years or so.



Edit: the answer was that passing the line.separator to Scala's background compile server broke. There are several issues with the compile server (which can be invoked with fsc for the "fast" scala compiler), which is now deprecated. The solution here, as always, is to use the -nc to request "no compile daemon" for your script. Compilation of the script takes a second longer, but you save hours or days of debugging.






share|improve this answer


























  • your best option seems to get me into the REPL, but if I pass a script path, if fails with 'Usage: fsc <options> ...'. Are you testing in a cygwin bash environment?

    – philwalk
    Nov 19 '18 at 19:40











  • Your -nc invocation suggestion works for me, if you write it up I'll mark your response as the solution.

    – philwalk
    Dec 7 '18 at 11:56











  • OK cool, that's weird enough to deserve an answer on SO. Personally, I gave up on fsc a long time ago and always use -nc (which is now a deprecated option because it is the default behavior).

    – som-snytt
    Dec 7 '18 at 13:25
















1














JAVA_OPTS is an ancient convention but not a standard. It was introduced to the scala script in 2007 and overtaken by -J in 2010.



I think the best option (so to speak) is scala -J-Dline.separator=$'r'$'n'.



There is a PR now for your suggestion, which seems safe, except it also keeps tab for the case:



JAVA_OPTS="-Xmx256m <tab> -Xss1m".



Shell quoting is so much fun! I try to refresh my scarred memory every five years or so.



Edit: the answer was that passing the line.separator to Scala's background compile server broke. There are several issues with the compile server (which can be invoked with fsc for the "fast" scala compiler), which is now deprecated. The solution here, as always, is to use the -nc to request "no compile daemon" for your script. Compilation of the script takes a second longer, but you save hours or days of debugging.






share|improve this answer


























  • your best option seems to get me into the REPL, but if I pass a script path, if fails with 'Usage: fsc <options> ...'. Are you testing in a cygwin bash environment?

    – philwalk
    Nov 19 '18 at 19:40











  • Your -nc invocation suggestion works for me, if you write it up I'll mark your response as the solution.

    – philwalk
    Dec 7 '18 at 11:56











  • OK cool, that's weird enough to deserve an answer on SO. Personally, I gave up on fsc a long time ago and always use -nc (which is now a deprecated option because it is the default behavior).

    – som-snytt
    Dec 7 '18 at 13:25














1












1








1







JAVA_OPTS is an ancient convention but not a standard. It was introduced to the scala script in 2007 and overtaken by -J in 2010.



I think the best option (so to speak) is scala -J-Dline.separator=$'r'$'n'.



There is a PR now for your suggestion, which seems safe, except it also keeps tab for the case:



JAVA_OPTS="-Xmx256m <tab> -Xss1m".



Shell quoting is so much fun! I try to refresh my scarred memory every five years or so.



Edit: the answer was that passing the line.separator to Scala's background compile server broke. There are several issues with the compile server (which can be invoked with fsc for the "fast" scala compiler), which is now deprecated. The solution here, as always, is to use the -nc to request "no compile daemon" for your script. Compilation of the script takes a second longer, but you save hours or days of debugging.






share|improve this answer















JAVA_OPTS is an ancient convention but not a standard. It was introduced to the scala script in 2007 and overtaken by -J in 2010.



I think the best option (so to speak) is scala -J-Dline.separator=$'r'$'n'.



There is a PR now for your suggestion, which seems safe, except it also keeps tab for the case:



JAVA_OPTS="-Xmx256m <tab> -Xss1m".



Shell quoting is so much fun! I try to refresh my scarred memory every five years or so.



Edit: the answer was that passing the line.separator to Scala's background compile server broke. There are several issues with the compile server (which can be invoked with fsc for the "fast" scala compiler), which is now deprecated. The solution here, as always, is to use the -nc to request "no compile daemon" for your script. Compilation of the script takes a second longer, but you save hours or days of debugging.







share|improve this answer














share|improve this answer



share|improve this answer








edited Dec 7 '18 at 13:24

























answered Nov 18 '18 at 7:42









som-snyttsom-snytt

34.9k233101




34.9k233101













  • your best option seems to get me into the REPL, but if I pass a script path, if fails with 'Usage: fsc <options> ...'. Are you testing in a cygwin bash environment?

    – philwalk
    Nov 19 '18 at 19:40











  • Your -nc invocation suggestion works for me, if you write it up I'll mark your response as the solution.

    – philwalk
    Dec 7 '18 at 11:56











  • OK cool, that's weird enough to deserve an answer on SO. Personally, I gave up on fsc a long time ago and always use -nc (which is now a deprecated option because it is the default behavior).

    – som-snytt
    Dec 7 '18 at 13:25



















  • your best option seems to get me into the REPL, but if I pass a script path, if fails with 'Usage: fsc <options> ...'. Are you testing in a cygwin bash environment?

    – philwalk
    Nov 19 '18 at 19:40











  • Your -nc invocation suggestion works for me, if you write it up I'll mark your response as the solution.

    – philwalk
    Dec 7 '18 at 11:56











  • OK cool, that's weird enough to deserve an answer on SO. Personally, I gave up on fsc a long time ago and always use -nc (which is now a deprecated option because it is the default behavior).

    – som-snytt
    Dec 7 '18 at 13:25

















your best option seems to get me into the REPL, but if I pass a script path, if fails with 'Usage: fsc <options> ...'. Are you testing in a cygwin bash environment?

– philwalk
Nov 19 '18 at 19:40





your best option seems to get me into the REPL, but if I pass a script path, if fails with 'Usage: fsc <options> ...'. Are you testing in a cygwin bash environment?

– philwalk
Nov 19 '18 at 19:40













Your -nc invocation suggestion works for me, if you write it up I'll mark your response as the solution.

– philwalk
Dec 7 '18 at 11:56





Your -nc invocation suggestion works for me, if you write it up I'll mark your response as the solution.

– philwalk
Dec 7 '18 at 11:56













OK cool, that's weird enough to deserve an answer on SO. Personally, I gave up on fsc a long time ago and always use -nc (which is now a deprecated option because it is the default behavior).

– som-snytt
Dec 7 '18 at 13:25





OK cool, that's weird enough to deserve an answer on SO. Personally, I gave up on fsc a long time ago and always use -nc (which is now a deprecated option because it is the default behavior).

– som-snytt
Dec 7 '18 at 13:25




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53343645%2fhow-to-set-jvm-property-line-separator-to-newline-from-bash%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Bressuire

Vorschmack

Quarantine