I would like to output the list of items in a folder in the folowing way:
\"filename1\" \"filename2\" \"file name with spaces\" \"foldername\" \"folder name wit
Try this.
find . -exec echo -n '"{}" ' \;
this should work
find $PWD | sed 's/^/"/g' | sed 's/$/"/g' | tr '\n' ' '
EDIT:
This should be more efficient than the previous one.
find $PWD | sed -e 's/^/"/g' -e 's/$/"/g' | tr '\n' ' '
@Timofey's solution would work with a tr in the end, and should be the most efficient.
find $PWD -exec echo -n '"{}" ' \; | tr '\n' ' '
EDIT:
The following answer generate a new-line separated LIST instead of a single line.
| tr '\n' ' '
)A less mentioned method is to use -d
(--delimiter
) option of xargs
:
find . | xargs -I@ -d"\n" echo \"@\"
-I@
captures eachfind
result as@
and then we echo-ed it with quotes
With this you can invoke any commands just as you added quotes to the arguments.
$ find . | xargs -d"\n" testcli.js
[ "filename1",
"filename2",
"file name with spaces",
"foldername",
"folder name with spaces" ]
See https://stackoverflow.com/a/33528111/665507