LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-19-2019, 10:45 AM   #1
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware 14.2 current / ArcoLinux / Void Linux
Posts: 8,863

Rep: Reputation: 1851Reputation: 1851Reputation: 1851Reputation: 1851Reputation: 1851Reputation: 1851Reputation: 1851Reputation: 1851Reputation: 1851Reputation: 1851Reputation: 1851
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.

Last edited by BW-userx; 06-19-2019 at 10:48 AM.
 
Old 06-19-2019, 10:57 AM   #2
Turbocapitalist
Senior Member
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 4,020
Blog Entries: 3

Rep: Reputation: 1918Reputation: 1918Reputation: 1918Reputation: 1918Reputation: 1918Reputation: 1918Reputation: 1918Reputation: 1918Reputation: 1918Reputation: 1918Reputation: 1918
The variables type1 and type2 are getting expanded by the shell and need to be quoted properly for find receive them verbatim.
 
2 members found this post helpful.
Old 06-19-2019, 11:15 AM   #3
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware 14.2 current / ArcoLinux / Void Linux
Posts: 8,863

Original Poster
Rep: Reputation: 1851Reputation: 1851Reputation: 1851Reputation: 1851Reputation: 1851Reputation: 1851Reputation: 1851Reputation: 1851Reputation: 1851Reputation: 1851Reputation: 1851
Quote:
Originally Posted by Turbocapitalist View Post
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...
(quoted everything but them ones)

thanks
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Etch giving me loads of hassle netstrider Debian 14 05-11-2007 03:44 AM
Konquerer menu bars giving hassle Pres Linux - Software 0 01-14-2003 07:47 AM
Audio hassle lachlan Linux - General 4 05-07-2002 04:14 AM
Redhat 7.0 install hassle! illegal Linux - Software 4 04-23-2002 08:52 PM
ISDN card hassle Richard Lucas Linux - Networking 1 12-10-2000 10:17 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:50 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration