echo ls -l -a / | xargs sh -c
How to make above command work?
it only list current directory
seems only ls is passed to xargs
echo '"ls -l -a /"' | xargs sh -c
would work though, but the input I got has no ""
The -c
flag to sh
only accepts one argument while xargs is splitting the arguments on whitespace - that's why the double quoting works (one level to make it a single word for the shell, one for xargs).
If you use the -0
or null
argument to xargs
your particular case will work:
echo ls -l -a / | xargs -0 sh -c