|
发表于 2003-11-14 00:29:21
|
显示全部楼层
最初由 javalee 发表
- [/home/javalee/myshell]for i in *
- > do
- > if [[ -f $i ]]
- > then
- > sed '1i\
- > abc' $i>tmp$i;rm $i;mv tmp$i $i
- > fi
- > done
复制代码
经测试(系统为gentoo shell为bash)该脚本对全空文件无效。
最初由 lordbyorn 发表
for file in *
do
(echo "this is a book" ; cat $file )>tmp
mv tmp $file
done
经测试如果当前目录中有子目录,则子目录下会出现tmp文件,内容为this is a book。个人建议加入判断if [[ -f $i ]],以过滤目录。 |
|