LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   find is giving me a hassle in a script (https://www.linuxquestions.org/questions/programming-9/find-is-giving-me-a-hassle-in-a-script-4175656027/)

BW-userx 06-19-2019 10:45 AM

find is giving me a hassle in a script
 
I should know this, I do suppose, but nevertheless, it has me stumped.
find not giving absolute path and file.
my script.
Code:

#!/bin/bash

set -xv


#June 2019
## for e16 in conjunction with its epplet eslides
#to change images upon start up of desktop
#for desktop background
#for arch type Linux systems
#placed in /usr/local/bin/e16loadbackgrounds
#called from e16 session.sh script
#

source1=/usr/share/backgrounds
source2=/media/data1/EtermBGs
source3=$HOME/.config/variety/Downloaded
source4=$HOME/.config/variety/Favorites
destination=$HOME/.e16/backgrounds

mkdir -p $destination
#remove old images and then add new ones

find $destination -type f -exec rm {} \;
amount=30

#image types
type1="*.png"
type2="*.jpg"

#check for dir presents then load if true

[[ -d "$source1" ]] &&
{ mapfile -t source1a < <(find "$source1" -type f \( -name $type1 -o -name $type2 \) | shuf) ; }

[[ -d "$source2" ]] &&
{ mapfile -t source2a < <(find "$source2" -type f \( -name $type1 -o -name $type2 \) | shuf) ; }

[[ -d "$source3" ]] &&
{ mapfile -t source3a < <(find "$source3" -type f \( -name $type1 -o -name $type2 \) | shuf) ; }

[[ -d "$source4" ]] &&
{ mapfile -t source4a < <(find "$source4" -type f \( -name $type1 -o -name $type2 \) | shuf) ; }


        #/usr/share/backgrounds
        #if array size is less than or equal to amount
        if [[ ${#source1a[@]} -le $amount ]] ; then
                #just put all of them in
                for (( i=0;i<${#source1a[@]};i++ )) ; do
                        cp ${source1a[$i]} $destination
                done #if array is greater than amount
        elif [[ ${#source1a[@]} -gt $amount ]] ; then
                for (( i=0;i<$amount;i++ )) ; do
                        #put some random images in directory
                        cp  "${source1a[$(( RANDOM % ${#source1a[@]} ))]}" "$destination"
                done
        fi
       
                #/media/data1/EtermBGs
        #if array size is less than or equal to amount
        if [[ ${#source2a[@]} -le $amount ]] ; then
                #just put all of them in
                for (( i=0;i<${#source2a[@]};i++ )) ; do
                        cp ${source2a[$i]} $destination
                done #if array is greater than amount
        elif [[ ${#source2a[@]} -gt $amount ]] ; then
                for (( i=0;i<$amount;i++ )) ; do
                        #put some random images in directory
                        cp  "${source2a[$(( RANDOM % ${#source2a[@]} ))]}" "$destination"
                done
        fi
       
        #$HOME/.config/variety/Downloaded
        #if array size is less than or equal to amount
        if [[ ${#source3a[@]} -le $amount ]] ; then
                #just put all of them in
                for (( i=0;i<${#source3a[@]};i++ )) ; do
                        cp ${source3a[$i]} $destination
                done #if array is greater than amount
        elif [[ ${#source3a[@]} -gt $amount ]] ; then
                for (( i=0;i<$amount;i++ )) ; do
                        #put some random images in directory
                        cp  "${source3a[$(( RANDOM % ${#source3a[@]} ))]}" "$destination"
                done
        fi
       
        #$HOME/.config/variety/Favorites
        #if array size is less than or equal to amount
        if [[ ${#source4a[@]} -le $amount ]] ; then
                #just put all of them in
                for (( i=0;i<${#source4a[@]};i++ )) ; do
                        cp ${source4a[$i]} $destination
                done #if array is greater than amount
        elif [[ ${#source4a[@]} -gt $amount ]] ; then
                for (( i=0;i<$amount;i++ )) ; do
                        #put some random images in directory
                        cp  "${source4a[$(( RANDOM % ${#source4a[@]} ))]}" "$destination"
                done
        fi
#to check to be sure it ran       
printf "%s ran me\n" > $HOME/rane16script

set -xv out put from the find part of it
Code:

#check for dir presents then load if true

[[ -d "$source1" ]] &&
{ mapfile -t source1a < <(find "$source1" -type f \( -name $type1 -o -name $type2 \) | shuf) ; }
+ [[ -d /usr/share/backgrounds ]]
+ mapfile -t source1a
++ shuf
++ find /usr/share/backgrounds -type f '(' -name '*.png' -o -name mpv-shot0003.jpg mpv-shot0023.jpg mpv-shot0024.jpg ')'
find: paths must precede expression: mpv-shot0023.jpg
Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]

[[ -d "$source2" ]] &&
{ mapfile -t source2a < <(find "$source2" -type f \( -name $type1 -o -name $type2 \) | shuf) ; }
+ [[ -d /media/data1/EtermBGs ]]
+ mapfile -t source2a
++ shuf
++ find /media/data1/EtermBGs -type f '(' -name '*.png' -o -name mpv-shot0003.jpg mpv-shot0023.jpg mpv-shot0024.jpg ')'
find: paths must precede expression: mpv-shot0023.jpg
Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]

[[ -d "$source3" ]] &&
{ mapfile -t source3a < <(find "$source3" -type f \( -name $type1 -o -name $type2 \) | shuf) ; }
+ [[ -d /home/userx/.config/variety/Downloaded ]]
+ mapfile -t source3a
++ shuf
++ find /home/userx/.config/variety/Downloaded -type f '(' -name '*.png' -o -name mpv-shot0003.jpg mpv-shot0023.jpg mpv-shot0024.jpg ')'
find: paths must precede expression: mpv-shot0023.jpg
Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]

[[ -d "$source4" ]] &&
{ mapfile -t source4a < <(find "$source4" -type f \( -name $type1 -o -name $type2 \) | shuf) ; }
+ [[ -d /home/userx/.config/variety/Favorites ]]
+ mapfile -t source4a
++ shuf
++ find /home/userx/.config/variety/Favorites -type f '(' -name '*.png' -o -name mpv-shot0003.jpg mpv-shot0023.jpg mpv-shot0024.jpg ')'
find: paths must precede expression: mpv-shot0023.jpg
Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]

the images it keeps getting are in my home parent dir. it should not even be looking at them it is not within the find path for any one of the finds. that I can see at the moment.

Turbocapitalist 06-19-2019 10:57 AM

The variables type1 and type2 are getting expanded by the shell and need to be quoted properly for find receive them verbatim.

BW-userx 06-19-2019 11:15 AM

Quote:

Originally Posted by Turbocapitalist (Post 6007173)
The variables type1 and type2 are getting expanded by the shell and need to be quoted properly for find receive them verbatim.

damn I must have ran out of quotes, now I got a go find some more to use in them... :rolleyes:
(quoted everything but them ones)

thanks


All times are GMT -5. The time now is 05:09 AM.