Solved scope confusion in Bash

why am I dropping the source variable value when I get into the resize_Images function?
output
Code:
[userx@FreeBSD ~]$ setupEtermImages
Enter a source path to images ~/Pictures

    /home/userx/Pictures
    is this the correct path? y/n y
find: : No such file or directory

script

Code:
#!/usr/bin/env bash

#Check for needed application first
[[ ! -x $(which mogrify) ]] && { echo "missing mogrify : install ImageMagick" ; exit ; }
[[ ! -x $(which unrar) ]] && { echo "missing unrar: need to install unrar" ; exit ; }
[[ ! -x $(which zip) ]] && { echo "missing zip: need to install a zip program" ; exit ; }

#Gets Monitor Dimensions for
#knowing what size to make images
getdimensions=$( xdpyinfo | grep dimensions | awk '{print $2}' )
#split the width and height into separate variables.
screenwidth=${getdimensions%x*}
screenheight=${getdimensions#*x}
#desired image width
width=$screenwidth

source=
destanation=
flag=false

while [[  $flag = 'false' ]]
do

    if [[ -z $imagePath ]] ;
    then
        read -p "Enter a source path to images " imagePath
    fi
        #to expand the tidle mark to users home dir  
    [[ $imagePath =~ '~' ]] && { imagePath=${imagePath/#\~/$HOME} ; }
      
    read -p "
    $imagePath
    is this the correct path? y/n " ans1
  
    case $ans1 in
    'y'|'Y')
        flag=true ;;
    'n'|'N')
        flag=false
        imagePath='' ;;
    esac
      
done

resize_Images()
{
    while read f
    do
        wh=$(identify -format "%wx%h" "$f")
        if [[ ${wh%x*} -gt ${wh#*x} ]] ; then
        {
            #wide images
            [[ $(identify -format "%[fx:w]" "$f") -gt "$width" ]] &&
            {     mogrify -resize "$width" "$f" ;
                echo " $f" ;
                size=$( identify -format "%wx%h" $f) ; }
        }
        else
        {  
            #tall images if not wide then it is tall so just resize
            #image if needed
                      
            [[ $(identify -format "%[fx:h]" "$f") -gt "$screenheight" ]] &&
            {     mogrify -geometry x"$screenheight" "$f" ;
                echo " $f" ;
                size=$( identify -format "%wx%h" $f) ; }
              
        }
        fi
        echo $wh
        echo $size
    done < <(find "$source" \( -type f -iname "*.jpg" -o -type f -iname "*.png" \) )
  
}

[[ $flag = 'true' ]] && resize_Images
 
The source variable never gets set to anything, it's defined but stays empty the whole time.
 
ga da.. I am so use to not programming my scripts like that , (using that first loop to keep asking until I get a correct response), I forgot I used two different varitable names for the same thing, too easy .. what was I thinking?
thanks for the two extra set of eye balls!!
 
Back
Top