I am very new to bash scripting first and foremost. I wrote a script that checks for entries inside of a directory and prints information about the entries. If the entries are files it prints the file size and if there are directories it prints how many items are in those directories. When I run the script against the directory it is located in the script completes successfully. If I run the script against another directory I receive the error "Binary operator expected". Is this to be expected? Here is the code:
#!/bin/bash
# Print the contents of a directory with details on files and directories
files=( $1* )
count=0
for entry in $1/*
do
if [ -d $entry ]
then
for f in $entry/*
do
let count=count+1
done
echo $entry ":" "This is a directory with $count files present."
let count=0
else [ -f $entry ]
echo $entry "This is a file of" $(wc -c <"$entry") "bytes."
fi
done
I'm sure this code isn't perfect and most likely has an easier method so I am just looking for some advice. Thank you for any help.
FurmanTheGerman
"$entry"and"$1") Second, proceed step by step and use#!/bin/bash -vor#!/bin/bash -xto see what's going on.