免费注册 查看新帖 |

Chinaunix

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

请问如何CP的时候不覆盖文件也不出现提示信息 [复制链接]

论坛徽章:
0
1 [报告]
发表于 2009-01-07 21:25 |显示全部楼层

回复 #14 我是DBA 的帖子

yes本身就是个命令

论坛徽章:
0
2 [报告]
发表于 2009-01-07 21:51 |显示全部楼层

回复 #16 biglazybug 的帖子



你这次的猫比较可爱,没有再虐待它了?

论坛徽章:
0
3 [报告]
发表于 2009-01-07 22:40 |显示全部楼层

回复 #21 我是DBA 的帖子


  1. [rockfall@localhost tmp]$ echo "">a.txt
  2. [rockfall@localhost tmp]$ more a.txt

  3. [rockfall@localhost tmp]$ cp -i ../sor ./a.txt
  4. cp: overwrite `./a.txt'? n
  5. [rockfall@localhost tmp]$ yes|cp -i ../sor ./a.txt    <==估计welcome008 是想这样用no吧?
  6. cp: overwrite `./a.txt'? [rockfall@localhost tmp]$ more a.txt
  7. id:0,count:18,doc:10,CHI:9,info:9.3897866898
  8. id:1,count:2813,doc:1186,CHI:8.8059808988,info:9.5329395664
  9. id:2,count:2627,doc:1193,CHI:10.4851413849,info:9.3680302230
复制代码

论坛徽章:
0
4 [报告]
发表于 2009-01-07 22:54 |显示全部楼层
刚才看yes时,看到一个等效脚本,改了个no的

  1. #!/bin/bash
  2. # no.sh

  3.   no ()
  4. { # Trivial emulation of "no" ...
  5.    local DEFAULT_TEXT="no"
  6.     while [ true ]     # Endless loop.
  7.     do
  8.        if [ -z "$1" ]
  9.        then
  10.           echo "$DEFAULT_TEXT"
  11.        else            # If argument ...
  12.           echo "$1"    # ... expand and echo it.
  13.        fi
  14.     done               # The only things missing are the
  15.   }

  16. no
复制代码

测试一下

  1. [rockfall@localhost tmp]$ cp -i ../sor ./a.txt
  2. cp: overwrite `./a.txt'? y
  3. [rockfall@localhost tmp]$ more a.txt
  4. id:0,count:18,doc:10,CHI:9,info:9.3897866898
  5. id:1,count:2813,doc:1186,CHI:8.8059808988,info:9.5329395664
  6. id:2,count:2627,doc:1193,CHI:10.4851413849,info:9.3680302230
  7. [rockfall@localhost tmp]$ echo "">a.txt
  8. [rockfall@localhost tmp]$ more a.txt

  9. [rockfall@localhost tmp]$ ./no.sh|cp -i ../sor ./a.txt
  10. cp: overwrite `./a.txt'? [rockfall@localhost tmp]$ more a.txt

  11. [rockfall@localhost tmp]$
复制代码


好像还行

echo "n"|cp -i a/xx b/

[ 本帖最后由 haimming 于 2009-1-8 00:37 编辑 ]

论坛徽章:
0
5 [报告]
发表于 2009-01-08 00:38 |显示全部楼层

回复 #25 welcome008 的帖子

呵呵,直接echo "n" 就可以了

论坛徽章:
0
6 [报告]
发表于 2009-01-08 00:41 |显示全部楼层

回复 #25 welcome008 的帖子

确实没盖!

论坛徽章:
0
7 [报告]
发表于 2009-01-08 00:46 |显示全部楼层
原帖由 dayan_he 于 2009-1-8 00:41 发表
我测试的也没覆盖

yes no|cp -i  a b


原来忘了yes的最基本应用了,呵呵

so,,,有了yes,就有了no,上面的脚本是多余的了,惭愧惭愧!

[ 本帖最后由 haimming 于 2009-1-8 00:49 编辑 ]

论坛徽章:
0
8 [报告]
发表于 2009-01-08 00:54 |显示全部楼层
你的cp有i参数吗?

没脑,问得太傻了!

[ 本帖最后由 haimming 于 2009-1-8 00:56 编辑 ]
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP