linux - How to use shell expr to count the number of files under a directory -
i want count number of files under directory using
if [ `expr ls -l $data_dir/*_1.data | wc -l` == 1 ] #blabla fi
but bash kept poping syntax error. did miss sth?
thanks.
with normal shells:
if [ "$(exec find "$data_dir" -maxdepth 1 -mindepth 1 -name '*_1.data' | wc -l)" -eq 1 ]; ... fi
with bash:
shopt -s nullglob files=("$data_dir"/*_1.data) if [[ ${#files[@]} -eq 1 ]]; ... fi
Comments
Post a Comment