编辑:
这是我更新的代码:
#!/bin/sh
files=`ls`
if [ $# -ne 1 -o -f $1 ]
then
echo "Usage: $0 <directory>"
exit 1
fi
if [ ! -e $1 ]
then
echo "$1 not found"
exit 1
elif [ -d $1 ]
then
cd $1
for f in $files
do
if [ ! -d "$f" ]
then
if [ ! -s "$f" ]
then
rm -r "$f"
echo "File: $f was removed."
else
continue
fi
fi
done
echo "NamettLinksttOwnerttDate"
for f in $files
do
find "$f" -type f -printf "%ftt %ntt %ut %TH %Tb %TYn"
done
exit 0
fi
我修复了所有的间距问题,将#!bin / sh更改为#/ bin / bash,并在“$f”中添加了引号.但是我仍然遇到很多错误.
ava@kosh:~/test$./delDir d1 rm:
cannot remove d1': No such file or
directory File: d1 was removed. rm:
cannot remove
delDir’: No such file
or directory File: delDir was removed.
rm: cannot remove delDir2': No such
file or directory File: delDir2 was
removed. rm: cannot remove
e1′: No
such file or directory File: e1 was
removed. rm: cannot remove e2': No
such file or directory File: e2 was
removed. rm: cannot remove
make_d1′:
No such file or directory File:
make_d1 was removed.
NamettLinksttOwnerttDate find:
d1: No such file or directory find:
delDir: No such file or directory
find: delDir2: No such file or
directory find: e1: No such file or
directory find: e2: No such file or
directory find: make_d1: No such file
or directory ne1 2
ava 22 Nov 2009 ne2
2 ava 22 Nov 2009
有谁知道我做错了什么?
Here’s my code:
06001
Here are my questions:
-
If I execute the script with something that is NOT an ordinary file
AND is NOT a directory I want it to
say “Usage: Filename directory” (see
line 5). I know I can do this with 2
if statements but is it possible to
create an or statement for this in
bash?
-
When I run the script I keep getting errors like this:
./delDir: 39: [!: not found ./delDir: 39: [!: not found ./delDir:
39: [!: not found ./delDir: 39: [!:
not found ./delDir: 39: [!: not found
./delDir: 39: [!: not found ./delDir:
39: [!: not found ./delDir: 39: [!:
not found ./delDir: 39: [!: not found
./delDir: 39: [!: not found Name
Links Owner Date
find: d1: No such file or directory
find: delDir: No such file or
directory find: delDir2: No such file
or directory e1 1
ava 22 Nov 2009 e2
1 ava 22 Nov 2009
find: make_d1: No such file or
directory ne1 2
ava 22 Nov 2009 ne2
2 ava 22 Nov 2009
??
??我相信我得到了这些错误
??因为for循环是第一次看
??用户输入的文件
??(它改变的目录)和
??找不到.怎么能解决这个问题?
??3.您还可以看到更多错误吗?