Bash Scripting "[!: Not found" errors and how to write a statement or

EDIT: Here is my updated code:

#!/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 "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 problems with the interval, changed #! bin / sh to # / bin / bash and added quotes to "$ f". However, I still get a lot of errors.

ava @kosh: ~/test $./delDir d1 rm: d1': No such file or directory File: d1 was removed. rm: cannot remove delDir ': : delDir . rm: delDir2': No such file or directory File: delDir2 was removed. rm: cannot remove e1 ': : e1 . rm: e2': No such file or directory File: e2 was removed. rm: cannot remove make_d1 ': : make_d1 . \t\tLinks\t\t\t\t : d1: : delDir: find: delDir2: directory find: e1: directory find: e2: directory find: make_d1: ne1 2
ava 22 Nov 2009 ne2
2 ava 22 2009

- , ?

:

#!/bin/sh
files=`ls`
if [ $# -ne 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 "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

:

  • script -, , , ": " (. 5). , 2 , bash?

  • script, :

./delDir: 39: [!: not found./delDir: 39: [!: not found./delDir:   39: [!: Not found./delDir: 39: [!:    . /delDir: 39: [!: not found   . /delDir: 39: [!: not found./delDir:   39: [!: Not found./delDir: 39: [!:    . /delDir: 39: [!: not found   . /delDir: 39: [!: not found
     find: d1:   find: delDir:   find: delDir2:    e1 1
  ava 22 2009 . e2
  1 ava 22 2009   find: make_d1:   directory ne1 2
  ava 22 Nov 2009 ne2
  2 ava 22 2009

, for , (, ) . ? 3. , ? >

+3
6

, script

files = `ls`

, , - , , .

ls .

+4

[ ] :

if [! -d $f]

-a, -o OR:

if [ ! -d $f -a -f $f ]
if [ ! -d $f -o -f $f ]
+10

[ !.

+5

, : [ . "[!", .

+2

... , bash, #! /bin/sh, , .

, /bin/sh POSIX bash "posixically correct" shell, ​​ . /bin/sh , bash , POSIX. , , , .

, /bin/sh == POSIX_ME_HARDER, .. yikes! == - :)

bash, #!/bin/bash

, singingwolfboy :)

+2

[, .

, , rm 23:

rm -r $f

, . script .

rm -r "$f"
+1

Source: https://habr.com/ru/post/1724315/


All Articles