问题描述
我想在如下因素的方式输出文件夹中的项目清单:
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 with spaces"
在换句话说,项目名称必须是单行线,通过空格用引号(单人或双人)包围并分割。
In other words, item names must be in a single line, surrounded with quotes (single or double) and divided by spaces.
我知道
find . | xargs echo
打印输出在一个单一的线,但我不知道如何添加各地的各项目名的报价。
prints output in a single line, but I do not know how to add quotes around each item name.
这code是BSH脚本的一部分。
因此,该解决方案可以是一组命令和使用的临时文件,用于存储中间输出
This code is part of a bsh script.The solution can therefore be a set of commands and use temporary files for storing intermediate output.
非常感谢您的任何建议。
Thank you very much for any suggestion.
干杯,安娜
推荐答案
这应该工作
find $PWD | sed 's/^/"/g' | sed 's/$/"/g' | tr '\n' ' '
编辑:
此应大于previous多一个高效
This should be more efficient than the previous one.
find $PWD | sed -e 's/^/"/g' -e 's/$/"/g' | tr '\n' ' '
@ Timofey的溶液将与在端部的TR工作,应是最有效的。
@Timofey's solution would work with a tr in the end, and should be the most efficient.
find $PWD -exec echo -n '"{}" ' \; | tr '\n' ' '
这篇关于如何输出文件名与单线引号包围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!