File names with spaces in BASH

前端 未结 7 1389
清酒与你
清酒与你 2020-12-03 07:54

I\'m trying to write script that\'ll crop and resize large photos into HD Wallpapers.

#! /bin/bash


for i in `ls *.jpg`
do
    width=`identify -format \'%w         


        
7条回答
  •  感动是毒
    2020-12-03 08:41

    Use read to circumvent the problem with spaces. It looks a bit unnatural to write the loop like this but it works better:

    find . -type f -iname "*.jpg" | while read i
    do
        # your original code inside the loop using "$i" instead of $i
    done
    

    with -iname you also get the jpg files that might have an extension with different casing like .JPG. "i" in "iname" means ignore casing.

提交回复
热议问题