for file in `find . -type f` ;do chmod a-x "$file"; done

sh/bash/dash/ksh/zsh等Shell脚本
回复
头像
wzssyqa
帖子: 4010
注册时间: 2008-04-07 17:36
来自: 泰安人在阜新

for file in `find . -type f` ;do chmod a-x "$file"; done

#1

帖子 wzssyqa » 2009-10-14 18:41

为什么遇到有空格的文件名就报错呢?

for file in `find . -type f` ; echo "$file" ;do chmod a-x "$file"; done
bash: 在未预料的“echo”附近出现语法错误

这是怎么回事?
头像
cnkilior
论坛版主
帖子: 4984
注册时间: 2007-08-05 17:40

Re: for file in `find . -type f` ;do chmod a-x "$file"; done

#2

帖子 cnkilior » 2009-10-14 19:46

代码: 全选

for file in `find . -type f` ; do echo "$file" ; chmod a-x "$file"; done
gzbao9999
帖子: 627
注册时间: 2008-11-08 18:34

Re: for file in `find . -type f` ;do chmod a-x "$file"; done

#3

帖子 gzbao9999 » 2009-10-14 20:33

#!/bin/bash
find . -type f|while read i;
do
echo "${i}"
chmod a-x "$i" ;
done

使用for来读入文件里的行时,会自动把空格和换行符作为一样分隔符,so...换while
注意格式,要么换行,要么象楼上加分号 :em06
气血鼓荡,身体发胀,偶飘上头,三时舒畅
头像
543082593
帖子: 234
注册时间: 2008-11-07 8:41

Re: for file in `find . -type f` ;do chmod a-x "$file"; done

#4

帖子 543082593 » 2009-10-15 17:03

wzssyqa 写了:为什么遇到有空格的文件名就报错呢?

for file in `find . -type f` ; echo "$file" ;do chmod a-x "$file"; done
bash: 在未预料的“echo”附近出现语法错误

这是怎么回事?
很显然啊 没有
do for语句一定不要忘记了 do啊 :em04
fall again
smooth criminal
they don't care about us
billie jean
beat it
dangerous
the lost children
childhood
ben
i will be there
speechless
she is out of my life
rock with you
...
LOVE U FOREVER
头像
hubert_star
论坛版主
帖子: 5373
注册时间: 2007-10-29 22:12
系统: OSX 10.9 + Ub 1304
来自: 江苏南京

Re: for file in `find . -type f` ;do chmod a-x "$file"; done

#5

帖子 hubert_star » 2009-10-15 17:05

chmod a+X or chmod a+x?

没去man过chmod?
佛经说,人有八苦: 生、老、病、死、求不得、怨憎、爱别离、五阴盛 故我苦!
圣经说,人有七罪: 饕餮、贪婪、懒惰、淫欲、傲慢、嫉妒和暴怒  故我有罪!

我这篇帖子里面没有任何攻击我们伟大的中华人民共和国政府和任劳任怨的人民公仆(和本论坛高素质的版主)的文字和含义;

特此声明!

有些事,我们明知道是错的,也要去坚持,因为不甘心;有些人,我们明知道是爱的,也要去放弃,因为没结局;有时候,我们明知道没路了,却还在前行,因为习惯了。

欢迎来我的新浪微博@me
回复