I need to write a simple homework script for my Unix 101 course. I need to take a directory name from the user, and list how many things are in it. For some reason it doesn't work and gets the next error message:
line 3: [: missing `]'
line 9: [: missing `]'
I tried a lot of things around the brackets. By the examples I found on the net, this should work though.
#!bin/bash
if [ $# -ne 1 ]
then
echo "Usage: $0 {dirname}"
exit 1
fi
if [ -d "$1" ]
then
echo `ls -l $1 | wc -l`
else
echo "$1 directory not found!"
fi
#!/bin/bash -xto debug it. – sputnick Oct 19 '12 at 0:24