Rob Elliot
01/02/2022, 11:42 AMorg.apache.commons.text.StringEscapeUtils?Joffrey
01/02/2022, 11:54 AMRob Elliot
01/02/2022, 12:04 PMjava.lang.ProcessBuilder(String... command), and print them in a form that could be passed to sh -c and would work. Single quotes around each string would mean replacing any single quotes in the string with '\'' - that might be all that's neededephemient
01/02/2022, 12:27 PMList<String>/vararg String methods of ProcessBuilder pass arguments to the executable directly, without going through shell, which avoids the need for escaping. why do you need something to pass to sh -c?Joffrey
01/02/2022, 12:31 PMsh -c is neededJoffrey
01/02/2022, 12:32 PMcmd, otherwise good luck with quotingephemient
01/02/2022, 12:32 PMRob Elliot
01/02/2022, 12:33 PMtoString purposes, really - I want to represent it in a way that is easy for me to read & copy into an actual shell if I want to play with it.Rob Elliot
01/02/2022, 12:34 PMephemient
01/02/2022, 12:34 PMtime which exists as a separate executable on many systems anywayRob Elliot
01/02/2022, 12:35 PMprivate fun String.escape() = if (contains(' ') || contains('\'')) {
"'${replace("'", "'\\''")}'"
} else thisephemient
01/02/2022, 12:38 PM\t are usually in $IFS tooephemient
01/02/2022, 12:38 PM!^ may special meaning depending on the shellRob Elliot
01/02/2022, 1:28 PMephemient
01/02/2022, 1:42 PMProcessBuilder("/bin/bash", "-c", "echo \"\${@@Q}\"", "-s", "<\$hello>", "world!\n").start().inputReader().readLine()
// returns '<$hello>' $'world!\n'
but note that the $'' syntax is Bash-specificephemient
01/02/2022, 1:42 PM