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 2ava 22 Nov 2009 ne22 ava 22 2009
d1': No such file or directory File: d1 was removed. rm: cannot remove
delDir2': No such file or directory File: delDir2 was removed. rm: cannot remove
e2': No such file or directory File: e2 was removed. rm: cannot remove
- , ?
:#!/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. , ? >
:
#!/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. , ? >
, script
files = `ls`
, , - , , .
ls .
[ ] :
[
]
if [! -d $f]
-a, -o OR:
-a
-o
if [ ! -d $f -a -f $f ] if [ ! -d $f -o -f $f ]
[ !.
!
, : [ . "[!", .
... , bash, #! /bin/sh, , .
#! /bin/sh
, /bin/sh POSIX bash "posixically correct" shell, . /bin/sh , bash , POSIX. , , , .
/bin/sh
, /bin/sh == POSIX_ME_HARDER, .. yikes! == - :)
==
bash, #!/bin/bash
#!/bin/bash
, singingwolfboy :)
[, .
, , rm 23:
rm
rm -r $f
, . script .
rm -r "$f"
Source: https://habr.com/ru/post/1724315/More articles:List Sort (Win32 / C ++) - c ++problem using xsl method for each - xmlWPF GUI / GUI Management - c #Screenshots of selenium using rspec - ruby | fooobar.comRDP over TCP proxy - proxyunnamed enum & typedef? - objective-cУникальные UUID из нескольких процессов на одной машине - pythonsqlalchemy does not create my foreign key - pythonHow many workflow work cycles should an Asp.Net application execute? - c #Solution Templates in VS2010 - templatesAll Articles