Emax2020
Emax2020

Reputation: 29

exercise: download queue in bash

I'm slowly learning Bash. I have the basic idea in mind, but I need the right syntax and putting things together. Was hoping someone here could help.

As an exercise, I am using a downloading queue tool, which is based on youtube-dl.

the script asks the user for a link. It takes the link, and stores it in link1. It increase the link count by one after each entry. As long as the user puts in links, variables are created (link1, link2 .... so on) and n, the number of links increase by one. When user hits "q", the loop exists and the script executes.

Something like this:

n=0
echo "enter your link. when done, press 'd' "
read link
n++

for $n 
do: youtube-dl link & wait; 
else 
 if user presses d, this loop should terminate

I know this is very vague, but was hoping I could get some guidance.

It's something like that. I can't wrap my head around it fully. Can someone maybe point me in the right direction?

Upvotes: 0

Views: 159

Answers (1)

Jose Figueroa
Jose Figueroa

Reputation: 31

If I am understanding you, try something like this. You don't really need the counter $n, since you can just add to an array and then loop through it just the same, without having to keep track of the size yourself. Of course instead of the echo $str you would want to add your own code there with the link.

input=""
arr=()
while [ "$input" != "q" ]
do
    read -p "Gimmy some input, 'q' to quit: "  input
    if [ "$input" != "d" ]
    then
        arr+=($input)
    fi
done

for str in ${arr[@]}
do
    echo "$str"
done

Upvotes: 1

Related Questions