struggling with cycling thru list - bash

Forum rules
Before you post please read this

struggling with cycling thru list - bash

Postby bulsatar on Sun Jun 01, 2014 9:32 am

Morning Everyone,

Found a bash script that I wanted to alter as it wasn't working correctly but don't know enough to get it working and have been fumbling around the net with no luck.

The original bit below outputs the entire list in one got and does not iterate thru each item:
Code: Select all
startFile="$(ls -1 "${wallpaperDir}" | egrep -i "\.(png|jpg|jpeg|bmp|gif)$" | head -n 1)"
endFile="$(ls -1 "${wallpaperDir}" | egrep -i "\.(png|jpg|jpeg|bmp|gif)$" | tail -n 1)"

for line in "$(ls -1 "${wallpaperDir}" | egrep -i "\.(png|jpg|jpeg|bmp|gif)$")"; do
if [ $(echo "${line}" | grep -c "$endFile") -eq "1" ]; then
   nextFile=$startFile
else
   nextFile="$(ls -1 "${wallpaperDir}" | egrep -i "\.(png|jpg|jpeg|bmp|gif)$" | grep -A 1 "${line}" | tail -n 1)"
fi
echo "
 <static>
  <duration>${timeDisplay}</duration>
  <file>${wallpaperDir}/${line}</file>
 </static>
 <transition>
  <duration>${timeTransition}</duration>
  <from>${wallpaperDir}/${line}</from>
  <to>${wallpaperDir}/$nextFile</to>
 </transition>" >> "${wallpaperDir}/background.xml"
echo -n "."
done


So I tried to move the list to an array object and iterate thru that instead but keep getting different errors (mainly because bash confuses the hell out of me and I have no idea what I am doing even after looking for hours at examples). Error happens when trying to setup the array

Code: Select all
filearray="(ls -1 "${Dir}" | egrep -i "\.(png|jpg|jpeg|bmp|gif)$")"

for line in "${filearray[@]}"; do


Thanks for any assistance, guidance, prayers....an explanation would be appreciated as I would like to wrap a little of my brain around bash and grep. Or even better if there was a good ide out there that used "normal" language to create a bash script would be great!
bulsatar
Level 2
Level 2
 
Posts: 69
Joined: Sun May 26, 2013 1:05 am

Linux Mint is funded by ads and donations.
 

Re: struggling with cycling thru list - bash

Postby bulsatar on Sun Jun 01, 2014 1:08 pm

nevermind. quit trying to use grep and made my life much easier!! Here is the link for the code I eventually got working: http://forums.linuxmint.com/viewtopic.php?f=42&t=168953
bulsatar
Level 2
Level 2
 
Posts: 69
Joined: Sun May 26, 2013 1:05 am


Return to Scripts & Bash

Who is online

Users browsing this forum: No registered users and 1 guest