Bash scripting “[!: Not found” error, and how to write or declare

Edit:
This is my updated code:

#!/bin/sh
files=`ls`
if [$# -ne 1 -o -f $1 ]
then
echo "Usage: $0 "
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< br /> fi
fi
done


echo "Name\t\tLinks\t\tOwner\t\tDate"

for f in $files
do
find "$f" -type f -printf "%f\t\t %n\t\t %u\t %TH %Tb %TY\n"
done
exit 0
fi

I fixed all the spacing issues and will #! bin/sh changed to #/bin/bash and added quotation marks in “$f”. But I still get a lot of errors.

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 removee1′: 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.
Name\t\tLinks\t\tOwner\t\tDate 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

Does anyone know what I did wrong?

Here's my code:

06001

Here are my questions:

  1. 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?

  2. < p>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 N ov 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

I believe I got these errors
because the for loop is the first time to look at
the file entered by the user
(the directory it changed) and
can't find it. How can this problem be solved?
3. Can you see more errors?

Another problem is that you do this at the beginning of the script

files = `ls`

But then you cd to another directory and try to loop $files to delete them-of course this will not work because you The directory has been changed.

Move the ls line after changing the directory.

Edit:
This is my updated code:

< /p>

#!/bin/sh
files=`ls`
if [$# -ne 1 -o -f $1 ]
then
echo "Usage: $0 "
exit 1
fi
if [! -e $1 ]
then
echo "$1 not found"
exit 1

elif [-d $1 ]
then
cd $1

for f in $files
do< br /> if [! -d "$f" ]
then
if [! -s "$f" ]
then
rm -r "$f"
echo "File: $f was removed."
else
continue
fi
fi
done


echo "Name\t\tLinks\t\tOwner\t\tDate"

for f in $files
do
find "$f" -type f -printf "%f \t\t %n\t\t %u\t %TH %Tb %TY\ n"
done
exit 0
fi

I fixed all the spacing issues and will #! bin/sh changed to #/bin/bash and added quotation marks in "$f". But I still get a lot of errors.

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 removee1′: 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.
Name\t\tLinks\t\tOwner\t\tDate 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

< /blockquote>

Does anyone know what I did wrong?

Here's my code:

06001

Here are my questions:

  1. 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?

  2. < p>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< br> 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

I believe I got these errors
Because the for loop is the first time I look at the file entered by the user
(the directory it changes) and
can't find it. How can I solve this problem?
3. Can you see more errors?

Another problem is that you do this at the beginning of the script

< pre>files = `ls`

But then you cd to another directory and try to loop $files to delete them-of course this will not work, because you have changed the directory.

Move the ls line after changing the directory.

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 5483 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.