Greetings, I just came over from LQO where I can't even log-in anymore
In an effort to build a guitar chords quiz I'm trying to code a bash script that
1- builds an array of one directory's contents
(about 300 guitar chord notation images images [prompts])
2- selects a random image from the array
3- screens it
4- sleeps X seconds
5- replaces image by one of same name from another directory
(the same about 300 guitar chord but this time notation + chordbox images)
6- loops Y times a cue/validation .mp3 sharing the name root from yet another directory
7- removes element from array
8- returns to 2 to select another random file from remainder of array
Latest edit of the rudimentary beginnings:
Because my bash in no flash in the pan I need to keep it extremely formatted and tutorial/verbose
All help appreciated, the above WORKS but is embare-assingly rudimentary
In an effort to build a guitar chords quiz I'm trying to code a bash script that
1- builds an array of one directory's contents
(about 300 guitar chord notation images images [prompts])
2- selects a random image from the array
3- screens it
4- sleeps X seconds
5- replaces image by one of same name from another directory
(the same about 300 guitar chord but this time notation + chordbox images)
6- loops Y times a cue/validation .mp3 sharing the name root from yet another directory
7- removes element from array
8- returns to 2 to select another random file from remainder of array
Latest edit of the rudimentary beginnings:
Bash:
#!/bin/bash
# repopulate promt directory from standard
cp /0/data/music/chordquiz/promptsrc/* /0/data/music/chordquiz/prompt
directory_path="/0/data/music/chordquiz/prompt"
while [ "$(ls -A "$directory_path")" ]
do
cd /0/data/music/chordquiz/prompt
array=( * ) #make new array from directory contents
#
#echo "${array[@]}" # will dump all elements of the array
size=${#array[@]} # assign size of array to variable 'size'
rfromsize=$(($RANDOM % size)) # # Pick an array element, rfromsize WAS 'index'before
echo $rfromsize $size > ~/r1-size1.txt
longelement=${array[$rfromsize]}
element=${longelement::-4} # remove (.png) extension extension from longelement to make element
#
# SHOW the PROMT image for element:
###################################
feh -x -g 540x924+1500+500 --zoom 300 /0/data/music/chordquiz/prompt/$element.png &
pid=$! # get pid of THIS command now backgrnd process
sleep 1s # wait X seconds
kill $pid # close this pid
#
# show image 2 of element:
feh -x -g 540x1596+1500+300 --zoom 300 /0/data/music/chordquiz/diags/$element.png &
pid2=$! # get pid of THIS command now backgrnd process
sleep 10s # wait X seconds
#
# LOOP the mp3 XY times while still showing image 2 of element
#mpg123 --loop 3 /0/data/music/chordquiz/mp3/$element.mp3
# only have the 1 mp3 so far
#mpg123 --loop 3 /0/data/music/chordquiz/mp3/B_3.mp3
pid3=$! # get pid of THIS command now backgrnd process
kill $pid # close this pid
kill $pid2 # close this pid
kill $pid3 # close this pid
#
# remove file from prompt directory
rm /0/data/music/chordquiz/prompt/"$longelement"
done
exit
Because my bash in no flash in the pan I need to keep it extremely formatted and tutorial/verbose
All help appreciated, the above WORKS but is embare-assingly rudimentary
Last edited:

