Hello!
I am needing some help with writing a bash script.
I am currently in the process of revising a podcast management script I wrote to add some new functionality. The way I have it set up now is purely with variables and explicitly stating the commands in the body of the script. This is not exactly efficient because I have about 20 individual podcasts to manage. I am trying to split some of the routines out into functions. But instead of just blobbing it all into one long file I want to split the different steps into different scripts that only execute if called. This leads to me needing to run a function in a script on an item in a different script. For instance:
The first part of my script checks the download folders for fresh podcasts and lists them in a file for the rest of the scripts to find them easy:
Code:
#!/bin/bash
#
# Step 1
# Check raw_podcasts for new podcasts
READFILE="/home/ben/podcasts/readfile"
# check for new podcasts
function check_raw_podcasts
{
for NEW_MP3 in $(find /home/ben/podcasts/raw_podcasts/*/*".mp3") ; do
echo ${NEW_MP3} >> ${READFILE}
done
for NEW_M4A in $(find /home/ben/podcasts/raw_podcasts/*/*".m4a") ; do
echo ${NEW_M4A} >> ${READFILE}
done
}
$(check_raw_podcasts)
After the readfile has been populated with new podcasts, step 2 of my script checks the readfile and runs the appropriate functions specific to which podcasts are in the list.
Code:
#!/bin/bash
#
# Step 2
# Check the readfile for new podcasts to work on
READFILE="/home/ben/podcasts/readfile"
BUZZ_DIR="/home/ben/podcasts/raw_podcasts/buzz_out_loud"
ENGADGET_DIR="/home/ben/podcasts/raw_podcasts/engadget"
MACOSKEN_DIR="/home/ben/podcasts/raw_podcasts/macosken"
function check_readfile
{
for PODCAST in $(cat ${READFILE} | grep "$BUZZ_DIR") ; do
$(buzz_out_loud)
done
for PODCAST in $(cat ${READFILE} | grep "$ENGADGET_DIR") ; do
$(engadget)
done
for PODCAST in $(cat ${READFILE} | grep "$MACOSKEN_DIR") ; do
$(macosken)
done
}
$(check_readfile)
I want the functions listed in Step 2 $(buzz_out_loud) $(engadget) etc. to be available from a separate script.
I've been scouring for a little bit and I've noticed that sometimes people put something like
Code:
import ../scripts/functions.sh
or something similar at the beginning of a script. Is that basically what I'm looking for? I'm having a little trouble sorting this out. Thanks for your help!
ben