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

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -