how to deal with arguments when executing a script
my code is:
#!/bin/bash
DIR="$1"
if [ DIR eq $1 ]
then
echo -n "total directories:" ; find $DIR -type d | wc -l
echo -n "total files:" ; find $DIR -type f | wc -l
else
echo " pass parameters"
fi
when I executed with the script name (./countfiledirs
) it's showing as:
./countfiledirs: line 4: [: DIR: unary operator expected
pass parameters
If I execute ./countfiledirs
without passing arguments it should have to show like:
pls pass arguments.
If I execute ./countfiledirs with passing arguments as ./countfiledirs /usr/share it should have to show output like:
total directories:145
total files:254