免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
123
最近访问板块 发新帖
楼主: ytsmtipe
打印 上一主题 下一主题

递归把一个目录包括子目录中的所有文件转换成unix格式 [复制链接]

论坛徽章:
0
21 [报告]
发表于 2009-06-09 14:21 |只看该作者
那是因为ls会判断输出连接到的文件类型,如果输出到终端,会根据终端的几何特征以不同的格式输出。如果连接到普通文件或者管道,或者是在命令替换中输出,那么就是每个文件名一行了。你可以试一下 ls | cat,或者直接ls | od -Ad -tc 看看有没有\n

论坛徽章:
0
22 [报告]
发表于 2009-06-09 14:27 |只看该作者

回复 #21 lululau 的帖子

明白了,十分感谢

论坛徽章:
5
2015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:50:282015年亚洲杯之朝鲜
日期:2015-03-13 22:47:33IT运维版块每日发帖之星
日期:2016-01-09 06:20:00IT运维版块每周发帖之星
日期:2016-03-07 16:27:44
23 [报告]
发表于 2009-06-09 14:38 |只看该作者
晕哦。

论坛徽章:
23
15-16赛季CBA联赛之吉林
日期:2017-12-21 16:39:27白羊座
日期:2014-10-27 11:14:37申猴
日期:2014-10-23 08:36:23金牛座
日期:2014-09-30 08:26:49午马
日期:2014-09-29 09:40:16射手座
日期:2014-11-25 08:56:112015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:49:0315-16赛季CBA联赛之山东
日期:2017-12-21 16:39:1915-16赛季CBA联赛之广东
日期:2016-01-19 13:33:372015亚冠之山东鲁能
日期:2015-10-13 09:39:062015亚冠之西悉尼流浪者
日期:2015-09-21 08:27:57
24 [报告]
发表于 2009-06-09 14:49 |只看该作者

回复 #21 lululau 的帖子

这个和ls无关哦,是 `` 或 $() 的问题。

  1.    Command Substitution
  2.        Command substitution allows the output of a command to replace the com-
  3.        mand name.  There are two forms:

  4.               $(command)
  5.        or
  6.               `command`

  7.        Bash performs the expansion by executing command and replacing the com-
  8.        mand  substitution  with  the  standard output of the command, with any
  9.        trailing newlines deleted.  Embedded newlines are not deleted, but they
  10.        may  be  removed during word splitting.  The command substitution $(cat
  11.        file) can be replaced by the equivalent but faster $(< file).

  12.        When the old-style backquote form of substitution  is  used,  backslash
  13.        retains  its  literal  meaning except when followed by $, `, or \.  The
  14.        first backquote not preceded by a backslash terminates the command sub-
  15.        stitution.   When using the $(command) form, all characters between the
  16.        parentheses make up the command; none are treated specially.

  17.        Command substitutions may be nested.  To nest when using the backquoted
  18.        form, escape the inner backquotes with backslashes.

  19.        If  the  substitution  appears within double quotes, word splitting and
  20.        pathname expansion are not performed on the results.
复制代码

论坛徽章:
5
2015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:50:282015年亚洲杯之朝鲜
日期:2015-03-13 22:47:33IT运维版块每日发帖之星
日期:2016-01-09 06:20:00IT运维版块每周发帖之星
日期:2016-03-07 16:27:44
25 [报告]
发表于 2009-06-09 14:49 |只看该作者

回复 #1 ytsmtipe 的帖子

try:
#!/bin/bash
IFS=$'\n'
...

论坛徽章:
5
2015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:50:282015年亚洲杯之朝鲜
日期:2015-03-13 22:47:33IT运维版块每日发帖之星
日期:2016-01-09 06:20:00IT运维版块每周发帖之星
日期:2016-03-07 16:27:44
26 [报告]
发表于 2009-06-09 14:53 |只看该作者
word splitting

论坛徽章:
0
27 [报告]
发表于 2009-06-09 15:06 |只看该作者

回复 #24 ly5066113 的帖子

这个我明白,暮木同学的疑问是为什么ls输出的结果本来是没有\n的,为什么echo "$(ls)"就有了\n
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP