How do I combine two functions into a single script? [SOLVED]

interpretive language scripts


Moderator: Forum moderators

Post Reply
User avatar
Jasper
Posts: 2067
Joined: Wed Sep 07, 2022 1:20 pm
Has thanked: 854 times
Been thanked: 480 times

How do I combine two functions into a single script? [SOLVED]

Post by Jasper »

Hi all

I have two scripts that I use. The first one downloads podcasts for me:

Code: Select all


#!/bin/sh
urxvt -e yt-dlp -f wa --external-downloader aria2c --embed-thumbnail --batch-file /root/download.txt --path /root/Downloads/Podcasts

Once I have my podcast, I use the second script to remove the unnecessary additional characters in the filename:

Code: Select all


#!/bin/sh
for file in *.m4a ; do
    head=${file#*[}     #part of file name up to (and including) left bracket '['
    find=[${head%]*}]   #pair of brackets with string (=the stuff that should be removed)
    rename  "$find" '' "$file"
done

In an ideal world I would like both to be combined so that I have a single script to run.

Can you inform me what needs to be done?

Both work perfectly, as is :D

Last edited by Jasper on Tue Dec 19, 2023 9:22 am, edited 1 time in total.
User avatar
Trapster
Posts: 182
Joined: Sat Aug 01, 2020 7:44 pm
Has thanked: 1 time
Been thanked: 53 times

Re: How do I combine two functions into a single script

Post by Trapster »

Unless I'm missing something, it should be as simple as putting your second script into the first.
Just remove the

Code: Select all

#!/bin/sh

from the second script and add to change to the Podcast directory

Code: Select all

#!/bin/sh
urxvt -e yt-dlp -f wa --external-downloader aria2c --embed-thumbnail --batch-file /root/download.txt --path /root/Downloads/Podcasts

cd /root/Downloads/Podcasts
for file in *.m4a ; do
    head=${file#*[}     #part of file name up to (and including) left bracket '['
    find=[${head%]*}]   #pair of brackets with string (=the stuff that should be removed)
    rename  "$find" '' "$file"
done


User avatar
Jasper
Posts: 2067
Joined: Wed Sep 07, 2022 1:20 pm
Has thanked: 854 times
Been thanked: 480 times

Re: How do I combine two functions into a single script?

Post by Jasper »

@Trapster

Thanks for that :thumbup:

Happy Holidays to you and your family 🎄🎄🎄🎄

User avatar
user1234
Posts: 414
Joined: Sat Feb 26, 2022 5:48 am
Location: Somewhere on earth
Has thanked: 155 times
Been thanked: 90 times

Re: How do I combine two functions into a single script? [SOLVED]

Post by user1234 »

I know this question is quite old; but for anyone searching for this same question, if you want to preserve both files, you can include either of the following in either of the script (you'll probably want this when each file has 100s of lines of code, and does it own separate job):

Code: Select all

. [path to your script]

Code: Select all

source [path to your script]

If anyone would ask me which to prefer, I'd say the above one since (i) it is shorter to write - just a single character, (ii) I have seen this used many times in woof-CE; and (iii) I think source is specific to bash only - I see in Kubuntu, . is a program in /usr/bin, while source is not.

Happy scripting :thumbup2:

PuppyLinux 🐾 gives new life to old computers ✨

Post Reply

Return to “Scripts”