I\'ve got a program that I want to call by passing parameters from a shell variable. Throughout this question, I am going to assume that it is given by
#!/bin/sh
This can be solved with xargs. By replacing
xargs
count-args $X
with
echo $X | xargs count-args
I can use backslashes to escape whitespaces in $X, e.g.
$X
X="Hello\\ World" echo $X | xargs count-args
prints out 1 and
X="Hello World" echo $X | xargs count-args
prints out 2.