简体   繁体   English

Bash 脚本 - 需要找到 output 文件路径的命令,用双引号括起来,不带换行符

[英]Bash Script - Need find command to output file paths enclosed in double quotes without line breaks

I have been using cscope/ctags database.我一直在使用 cscope/ctags 数据库。 However after sometime I noticed that some files in my cscope.files that stores the result of my find command, are broken into two or more lines.但是过了一段时间,我注意到我的cscope.files中存储我的 find 命令结果的一些文件被分成两行或多行。 This causes them being ignored by cscope/ctags while indexing.这会导致它们在索引时被 cscope/ctags 忽略。

Currently I use it in an alias:目前我在别名中使用它:

alias prp_indx='
    rm cscope.in.out cscope.out cscope.files tags
    find . -name '\''*.[chS]'\'' >> cscope.files
    find . -name '\''*.cpp'\'' >> cscope.files
    find . -name '\''*.hpp'\'' >> cscope.files
    find . -name '\''*.cxx'\'' >> cscope.files
    find . -name '\''*.hxx'\'' >> cscope.files
    cscope -b -q -k; ctags -R
'

Please help me with an appropriate command that I can use in my alias/function to achieve the file names with double quotes without paths broken in many lines.请帮助我使用适当的命令,我可以在别名/函数中使用该命令来实现带双引号的文件名,而不会在多行中破坏路径。

There is no reason I can think of for find to split the file names in several lines, except if the names themselves have newline characters in them.我没有理由想到 find 将文件名分成几行,除非名称本身包含换行符。 If it is the case it is probably better to rename these files.如果是这种情况,最好重命名这些文件。 Else there must be something else that tampers with your cscope.files file.否则一定有其他东西篡改了您的cscope.files文件。

Prefer a function.首选 function。 Compared to functions aliases mainly have drawbacks.与函数相比,别名主要有缺点。 With a bash function:使用 bash function:

prp_indx () {
  rm cscope.in.out cscope.out cscope.files tags
  find . -name '*.[chS]' -o -name '*.[ch]pp' -o -name '*.[ch]xx' > cscope.files
  cscope -b -q -k
  ctags -R "$@"
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM