Thank you all for your assistance - I really appreciate it. Things seem to be running smoothly at this point and are to my liking. Here is the finished version of the script:
Code:
#!/bin/bash
#######################################################################
## ##
## This script will play and repeat either one or more audio files ##
## that are contained in the current working directory. ##
## *Script requires that mplayer and figlet are installed. ##
## author: Darrin Goodman ##
## email: hilltopyodeler@gmail.com ##
## ##
## This program is free software and is available without warranty. ##
## You are free to redistribute it and/or modify it under the terms ##
## of the GNU General Public License as published by the ##
## Free Software Foundation, either version 3 or any later ##
## version of the license. ##
## ##
#######################################################################
## Set up trap so that it will allow you to terminate the script at any time using CTRL+C
## https://www.unix.com/shell-programming-scripting/244861-bash-question-howto-exit-script-user-input-while-process-running-mid-loop.html
trap 'exit 1' 1 2 3 15
###############################################################################
## BEGIN FUNCTIONS SECTION
doWhat()
{
echo -n "Repeat one file (1) or many files (M)? "
read quantity
echo ""
case $quantity in
1) oneFile ;;
m|M) manyFiles ;;
q|Q) quitski ;;
*) incorrectEntry ;;
esac
}
repeatNum()
{
echo -n "Enter the number of times you would like to play the file(s): "
read num
echo ""
}
oneFile()
{
echo -n "What is the name of the file? "
read file
echo ""
checkFile
repeatNum
echo "-------------------------------------------------------------------------------"
echo "-------------------------------------------------------------------------------"
echo ""
for ((i=1; i <= $num; i++))
do mplayer $file;
done
again
}
checkFile()
{
## Check to make sure that the file exists
if [ ! -f $file ]; then
echo " Hmmm... [ $file ] - This file does not exist; did you type it correctly?"
echo ""
oneFile
else
echo ""
fi
}
manyFiles()
{
echo -n "Enter the file type or extension (mp3 / ogg / *) "
read ext
echo ""
repeatNum
echo "-------------------------------------------------------------------------------"
echo "-------------------------------------------------------------------------------"
echo ""
for ((j=1; j <= $num; j++))
do mplayer *.$ext;
done
again
}
incorrectEntry()
{
echo " **************************************"
echo " * *"
echo " * INVALID ENTRY! Please try again. *"
echo " * *"
echo " **************************************"
echo ""
doWhat
}
again()
{
echo "-------------------------------------------------------------------------------"
echo "-------------------------------------------------------------------------------"
figlet "Done."
figlet "What next?"
echo "-------------------------------------------------------------------------------"
echo "-------------------------------------------------------------------------------"
echo ""
echo -n "What would you like to do now? ....Start over (s) or Quit (q)? "
echo ""
read whatNow
case $whatNow in
s|S) doWhat ;;
q|Q) quitski ;;
*) echo "Huh?" ; again ;;
esac
}
quitski()
{
clear
echo ""
figlet Good Bye!
echo ""
echo ""
exit
}
## END FUNCTIONS SECTION
###############################################################################
## Clear the screen
clear
figlet "Music Repeater"
echo "-------------------------------------------------------------------------------"
echo "This program will play one or more audio files, however many times you specify."
echo "Exit this script at any time with CTRL+C."
echo ""
## What do you want to do? Repeat one or many files?
doWhat
## End of program; exit
figlet END
# Reset all traps
trap - SIGINT SIGQUIT SIGTSTP
exit 0
This script suits my needs well. There may be more efficient ways to code this process, so please feel free make appropriate changes and re-post it if you like, and feel free to use it if it benefits you in some way.
Thanks again to those of you who offered assistance with getting the script to terminate with CTRL+c.
I have multiple input files that I want to manipulate using a shell script. The files are called 250.1 through 250.1000 but I only want the script to manipulate 250.300 through 250.1000. Before I was using the following script to manipulate the text files:
for i in 250.*; do
|| awk... (4 Replies)
Need help in scripting . Below is the situation and need your inputs
Checking all the processes, scripts running time based on user input time . Below Example
ps -aef -o user,pid,etime,stime,args| grep sleep
<user> 28995 01:24 14:14:39 sleep 120
<user> 29385 00:52 14:15:10... (8 Replies)
Hi Sir,
I am just learning bash scripting and I came across a challenge.
I need to input F11 to a script among many text inputs.
For all the text inputs i did following.
# sh test.sh < input.txt
where input.txt contains all the text inputs in new lines.
This worked fine until i... (1 Reply)
I'm writing a bunch of scripts to automatically configure Ubuntu and I want to run the code below to remove the white dots from the login screen:
sudo xhost +SI:localuser:lightdm
sudo su lightdm -s /bin/bash
gsettings set com.canonical.unity-greeter draw-grid false
The problem is that... (3 Replies)
I want to run a script that calls remote ssh and if it gets hung, I want to be able to kill that part of the script and run another command in the script
for example I have a statement like this:
if ];
then
export tapes=$(for tape in $(su - nacct -c 'ssh remote1 "cat... (1 Reply)
Heyas,
Since this question (similar) occur every now and then, and given the fact i was thinking about it just recently (1-2 weeks) anyway, i started to write something :p
The last point for motivation was... (17 Replies)
I have the following while loop that I put in a script, demo.sh:
while read rna; do
aawork=$(echo "${rna}" | sed -n -e 's/\(...\)\1 /gp' | sed -f rna.sed)
echo "$aawork" | sed 's/ //g'
echo "$aawork" | tr ' ' '\012' | sort | sed '/^$/d' | uniq -c | sed 's/*\(*\) \(.*\)/\2: \... (3 Replies)
Hi everyone, I'm new here and just a beginner in linux scripting.
Just want to ask for help on this one.
I am trying to create a script that will accept user input (year-month and user/s).
I wanted to have the script to continue running, until the user inputs a DATE and name/s of user/s. ... (2 Replies)
Hello,
I am running a bash script to do an rsync back on a computer running MacOS High Sierra. This is the script I am using,
#!/bin/bash
# main backup location, trailing slash included
backup_loc="/Volumes/Archive_Volume/00_macos_backup/"
# generic backup function
function backup {... (12 Replies)