I'm writing a bash script to do something if the directory has files of extensions: jpg, jpeg or png. But I'm screwing up when I try to check this with the for or while loops.
while [ filename in $IMAGE_DIR/*.jp*g -o filename in $IMAGE_DIR/*.png ] ; do
# do something here
But I receive compile error:
line 30: [: too many arguments
I tried the following loops to no avail.
for (filename in $IMAGE_DIR/*.jp*g) || (filename in $IMAGE_DIR/*.png); do
while [ filename in $IMAGE_DIR/*.jp*g ] || [ filename in $IMAGE_DIR/*.png ] ; do
while [[ filename in $IMAGE_DIR/*.jp*g ]] || [[ filename in $IMAGE_DIR/*.png ]] ; do
while [[ filename in $IMAGE_DIR/*.jp*g ] || [ filename in $IMAGE_DIR/*.png ]] ; do
while (( filename in $IMAGE_DIR/*.jp*g )) || (( filename in $IMAGE_DIR/*.png )) ; do
while ( filename in $IMAGE_DIR/*.jp*g )) || (( filename in $IMAGE_DIR/*.png ) ; do
What am I missing here?
do_something *.jpg *.jpeg *.pngif there aren't any, you will do_nothing. Or usefind -name "*.jpeg"or any other pattern you want for their name, andxargsthem to your job. There is no reason to check all the filenames around, the shell offers you these files with one command or one glob.do something if the directory has files of extensionsor do you want to iterate over these files? If this a duplicate of stackoverflow.com/questions/6363441/… ?