In a POSIX sh, or in the Bourne shell (as in Solaris 10's /bin/sh
), is it possible to have something like:
a='some var with spaces and a special space'
printf "%s\n" $a
And, with the default IFS
, get:
some
var
with
spaces
and
a
special space
That is, protect the space between special
and space
by some combination of quoting or escaping?
The number of words in a
isn't known beforehand, or I'd try something like:
a='some var with spaces and a special\ space'
printf "%s\n" "$a" | while read field1 field2 ...
The context is this bug reported in Cassandra, where OP tried to set an environment variable specifying options for the JVM:
export JVM_EXTRA_OPTS='-XX:OnOutOfMemoryError="echo oh_no"'
In the script executing Cassandra, which has to support POSIX sh and Solaris sh:
JVM_OPTS="$JVM_OPTS $JVM_EXTRA_OPTS"
#...
exec $NUMACTL "$JAVA" $JVM_OPTS $cassandra_parms -cp "$CLASSPATH" $props "$class"
IMO the only way out here is to use a script wrapping the echo oh_no
command. Is there another way?