 hey everybody welcome back to the channel today we're going to be making some we're gonna have some scripting fun um there's a couple things before we get started the first thing we're gonna I should say is we're going to be doing writing a music tagging script today in bash and that being said I want to say two things one I am not a bash expert I don't know everything about bash so there's chances are we're gonna be going through this and there's gonna be some things that aren't gonna work so I might have to do some research right here on live on the video that's the way scripting works for most people unless you're like a super duper expert I am not one of those people um second thing like with all tutorials on this channel take the term tutorial with a grand assault um if you learn something that's great I hope you do if you learn what not to do which is more likely um also good that's then I've served my purpose on earth and you will have uh you know learned from my mistakes or possibly learned something you know you know how to do something that's good keep hydrated anyways basically the idea for the script today let's go ahead and clear some stuff here and get back to the main screen so that you can actually see what I'm doing so basically the idea is what I want to do is I want to be able to ask the user the terminal user for the name artist album and so on and then have a program which is called ID3 have that program go through and assign that information that the user entered into the appropriate places into a string and assign those tags to a particular file so um whether or not this works or not we're going to find out um so I've already created the file so basically to do that I just did touch music and then I then the second thing I did was chmod and music okay I'm not going to do those again because I've already done that um mainly because this is my second time recording this video because I forgot to change the output in obs to the screen I was still recording the the beginning screen now um nobody ever said I was smart anyway so we just if we're gonna v into music here oops and the only thing I have so far is the shebang any script that you start start at least it's a shell script I should say starts with a shebang which is just you know hashtag exclamation point slash bin slash sh you can also do slash zsh slash bash because those are posits compliant shells you should be able to use the same syntax in all three of those now it's a little bit different if you're using a shell like fish the syntax there is different you can't use the equal signs you can't use um certain symbols because fish doesn't recognize those because it's not posits compliant and that's the reason why we don't use fish so a little bit of rant over there what we're going to do now is do the beginning input so basically what we want to do is echo and then quotation marks what is the title of the song okay and then we want to do we want to do this read single quotation marks oops we had a couple flags dash e dash p single quotation marks and I'm gonna actually try something I want to do title and artist I want to see if this will work it may not work um and if it doesn't work I'm not question why I get it remember I'm not an expert at this we're just gonna we're gonna try if it doesn't work we'll have to do them separately so um title artist okay so um oh you want to know it I think I know what this is okay so we do do a a semicolon here leave a space and this is the dollar sign zero dollar sign one okay so it's gonna gonna store whatever output the user enters the first word will be a variable zero the second one will be variable dollar sign and just to see if this works before we continue on we don't want to go we just want to echo zero and dollar sign one we will save that and make this a little bit bigger and we will do dot slash music is not available line five is not does not work okay so syntax there's obviously wrong okay I wonder why let's wonder why that won't work okay okay we'll we'll try this and we're blatantly copying some somebody's stuff here let's see if this works basically what this says if dollar sign one contains something then echo this so we're gonna change inside oops change inside quotation marks and we're just gonna do dollar sign one okay otherwise positional we'll just leave that point and we'll comment this out for now okay try it again okay so it did do this but line five is still wrong it's this one here that it's bother it is dot slash read oh I know exactly what's wrong I know it's exactly what's wrong okay get that close a little bit and we're gonna do here is remove the dash E flag and see if that's right I think because that dash E flag is to have file name tag autocomplete and because this isn't a tag isn't a path or something I think this should work not still won't work so maybe you want it's delete p2 still no obviously doing something wrong obviously doing something wrong um this is up and okay so let me look at my example again that's uh okay so I should say that I'm not writing this from an example of somebody else's script I'm looking actually at one of my other scripts that where I learned how to do some of this stuff which of course oh I'm done these don't need dollar signs I'm gonna go ahead and put dash E and dash P here again we'll see if this works it probably is still not going to work but we're gonna try this is how it goes still doesn't work zero is not a valid identifier okay all right well we're gonna have to do it set separately then until I learn how to do positional arguments which I apparently still don't know how to do which is just the way of things why aren't my key bindings working that's okay you aren't fine my key binding stopped working that's really weird make sure I'm not in a mode anyways we'll just delete this dude nothing's working I can't type all right so we're just gonna call this title okay and we delete these seriously nothing's working and then to make sure this works cut echo dollar sign title I've been using DWM for like the last I don't know week and I've forgotten all my key bindings and I3 it's been annoying me all day long try this again okay breaking Benjamin that works of course it works because that's you'd expect it to work okay good okay we're just gonna have to do this the hard way so delete this line okay good now we're just gonna do this several times to define our variable so we'll echo what is the name of the artist read oops read dash e p artist oops these need to be single quotes artist okay and echo what is the the name of the album read dash e dash p album album echo what is the year of publication read dash e dash p here here okay echo what is the genre oops no we're gonna leave the genre because genre is different because in id3 which is the program we're gonna be using in genre they have to go through and use specific numbers which are looked up in some database somewhere I'm gonna leave that blank for just now I'm not sure if I'll add that or not we'll see so we did title artist album publication year and do you have a comment you have a comment and we'll be read dash e dash dash p comment I can't type I really can't type today this is a bad time to learn that you can't type okay so that's all really simple I would love to be able to learn how to combine these and uh the little bit of research I did before this evidently was enough um many programs so I'm reading a linux linux command.org which is basically like the bible of bash scripting just bear with me for a minute I'm looking here I want to see if we can get my nose unfortunately this is the tutorial is not doing exactly what I want to want us okay so this person does echo a phrase loop until all parameters are used up echo one do echo parameter one equals one you now have the shift shift fascinating okay all right well you want to we're gonna go try that just I told you you'd we'd be learning alongside each other so I'm going to save this because we know this will work we know this will work but it's messy so we're going to quit and we're going to touch a m2 we're just going to call this m2 and we're going to chmod m2 and then m2 okay and we're going to do a shebang so in insert mode pound sign exclamation point slash bin slash bash this shs it doesn't matter okay and then according to this handy dandy website I have this is what we need to do um something like this oops undo oops I just can't do anything all right that this isn't gonna work either because this is this is going because I don't really understand I guess basically what this does is it assigns this variable here back down here but then allows it to shift all right well that's not going to work for us I'm gonna have to keep doing some I'm gonna have to keep doing some research on positional organs so this is just gonna be v1 of this script so we'll be back into music oops okay so basically what we want to do now is ensure that all these things work it should work echo dollar sign title dollar sign artist dollar sign album dollar sign year and dollar sign comment okay we'll make sure this is bigger and what is the name of the song breath by breaking the Benjamin album is um pulling this out I'm pretty sure it's uh saturate but that's not right it doesn't matter and that came out like 2003 or some crazy amount of time ago and no and that echoed everything out the way it should have good good very good now it's just a matter of plugging that into an id3 command so we will delete this line here because we don't need it okay what we need to do now is do this insert id3 dash t is going to be quotation marks dollar sign title okay uh dash a which is for artists is dollar sign artist okay and uh let's see dash uh l is dollar sign album why it's dash l i'm not sure probably because dash a was already taken dash and hope we're gonna do the track we gotta do a track echo what is the track number okay read dash e dash p track number okay dash n is going to be dollar sign track for those people who are bash experts you'll know that uh this is obviously the the hardest way of doing this because there is a way to combine these things I just still haven't figured it out as you you know repeatedly seen the last five minutes okay so that was dash n dash y is year dollar sign year okay and comment is dash c dollar sign comment okay so that should work there now one thing we did forget up here we need the path of the uh the song we want to do so we're gonna do echo what is the path of the song now there's a couple way I could do this the way I'm going to do it is just ask for the person to type in the path but we could also just do um uh because pwd is um print working directory so the but that would only work if the person was in the directory of where the song was at um and I don't want to limit that to this so what I'm just going to do is you read dash e oops dash p path and you go let's call this path and we need to add that to the end of this so dollar sign path okay so what we're going to have to do next is find this go here and save this and make this smaller you know this is way easier if I just do tabs I keep forgetting that I don't have to that I have tabs again you don't have tabs indeed of you without doing some crazy magic voodoo nonsense so um I forgot that I had tabs I have tabs it's great anyway so what we're going to do is I'm going to go find some music over here I gotta wait for my external hard drive to spin up like a cave man give me a second I'm gonna take a drink really honestly my hard drive should have already been spun up because I just did this before I started video recording but what are you gonna do all right we're there all right so if we do this again what is the path of the song so in this case it's dash run media dr m dub you a big boy music media music and then um let's just say do do do do do we'll go into uh three doors down and then uh I see 1997 with this one here and that's the that's the path of the song oh you want this is not gonna quite work because the path of the song also includes the title of the song so we we can do this but it's gonna we can make it easier in a minute so we'll just do um 01 kryptonite okay what is the title of the song kryptonite okay that's the title of the song I forgot colon there what is the name of the artist three doors down what is the name of the album name of the album is um three doors down okay what is the track number it's one okay what is the year of publication 1997 and do you have a comment no that's interesting that's really weird why did that should have worked let's go back and see what we did wrong okay so what was it what was that out there no files matching that shouldn't okay so let's just do id three dash one um and then uh let's cd into that file cd shesh run media diagrammed up big boy media music three doors down 1997 the cd there do ls and then we'll do id 33 dash one 01 so that are those already have tags but it still should work why didn't work because let's just all right so let's go ahead and try it just here so id three um dash t is kryptonite dash a looks like i put parentheses kryptonite dash a three doors down dash l three doors down dash year 1997 okay so obviously the reason why i have this is because dash t is not a valid option that's is that because i did i that's because i did i three i really got to learn not to you know do typos i wonder if i did this in the same thing i d three id three missing file arguments okay oh it's because you got to do uh this um 01 that worked okay that worked so that means we have a typo in this somewhere id three dash t id three dash t that's exactly what i did id three dash t parentheses in dollar sign title that should really work i wonder it has something to do with the path it has something to do with the path or i'm missing a quotation mark somewhere but then would tell me if i was missing an id a pass i'm going to save this again oops and we're going to go here i'm going to do dot slash dot that's not that's that was done you have to do till the dot slash no i don't know i'm a linux noob but it still should work it should work from any path because that because it doesn't require quotation marks around this in the real you know thing so i shouldn't have to put parentheses in this art so you want to let's do this i want what i want to do is remove so id id three um dash two delete crypt 01 that will remove the tags of the v2 of the of tags okay so um let's see back to home directory and dot slash this here and this should work if everything goes we just do this what is the path of the song slash run uh media dr m dub big boy media music uh three doors down 1997 and kryptonite 01 okay that's the path was the title of the song kryptonite what is the name of the artist three doors down three doors down 19 oops this is one 1997 no but we're going to type one anyways that still didn't work no files matching no files matching cd slash run yeah that's exactly that's that's the it has to have that slash in front of it why is it not working this doesn't make any sense i'm sure i'm doing something stupid let's go back over here id three dash t i have to be missing something dollar sign path you should store the whole path right here in the path variable and then it should just echo path you're not fine we will do this we'll comment this out i want to do echo dollar sign path let's do this we're just gonna do slash home it should home home home doesn't matter literally that's exactly what it should do is echo the path which is what it does so we know it's storing the variable correctly the question is why isn't it then putting it here where it should id three id three dash dash two all right we can do this title and see if that will work i know you want to want i think there has to be some print some quotation marks around stuff i think there has to be quotation marks here let's try it again slash run media document this is going to be a pain in the butt we're going to figure out a way to shorten this um big boy media music three doors down 1997 01 kryptonite okay was the name of the song kryptonite three doors down three doors down one 1997 good song okay i think it worked i think the entire problem was the lack of quotation marks around the path so if we go to now if we cd into slash run media dot get this one here and we do um id three dash two and then 01 ha ha it works look at that it works the dumbest problem ever just shows you that if you don't remember the syntax of every little thing it just doesn't work so that is literally the uh the script that i wanted to write there are several things i wanted to do i want to learn how to do uh positional arguments so that's my next task um i said well before we had this problem with the path i said there was something that i could do to make this better i don't remember what it was um first we need to go up here make sure there's a semicolon here because that was annoying um but there was something i don't i should have tried to write it down i don't remember what what i said that i could make this easier okay what i'm going to try to do is because because this pat because this script is basically just for me i'm i'm i'm going to share this but and i'll probably go through and do some commenting before put it upon github because i will put this up on github it'll be my script folder on github um but because it's mostly just for me i'm going to comment this line out here and this line out here and what i'm going to do is declare a variable which would be path equals dollar sign parentheses pwd okay okay so path is pwd so that's just basically the working directory and what we want to do down here is path slash title okay that may not work because the when i type in the title here i'm not going to be including any extraneous uh things like the because in the file name a lot of times you'll have the extraneous information like the track the track name and any other number of things that were down you know put in the the file name when you downloaded the the music so that may not work let me think about this for a second because the print working directory is not going to pick up the entire thing it's not going to pick up the name of the song i want to get around having to type in that whole gigantic path every single time what we could do is declare another variable instead of having it title type in um we're going to call fn equals no so what we do is echo we'll do this echo what is the name of the file okay and then read dash e dash p fn and we call this fn okay and this should be i should be able to use tab completion on this so we go down here and do this change word fn okay that should work we're going to find out right now okay so we want to do is ls in this okay so we want to um id three dash two d zero two okay we'll remove the tags from this so if we go up here and then list those you should have no version two tags which is good okay so we know now if the script works um of course now i'm gonna have to figure out remember how to do a script from what i think i'm going to do is uh is uh some move music to just slash home so if we just do dot slash music i can never remember how to run up up you want to find we're just gonna cp all right i'm gonna move music cp move music to slash local slash user local bin damn music users local bin all right yeah you can't see me doing it some of my other monitor i'm sorry so what we want to do here is do music okay what is the name of the file zero two losers i tab completion good we don't want to space at the end okay no space at the end and the title of the song is loser what is the name of three doors down what's the name of elm three doors down track number is two year was 1997 i don't have a comment so now if this worked if this worked we should be able to id three dash two damn on this haza it's always so much fun when things work i love it when a plan comes together even if it was a dumb plan so that is our script that ensures we don't have to go through and type in the horrendous long pass now this script will only work from the directory that the song is in so if you download this script to use as your own i don't know why you'd want to but if you do uh just know that this script will only work from the directory the song is in because it's that print working directory is going to mess up everything if you're not in the directory uh you know because it's just gonna then it's gonna pass the pass the wrong path into this argument here and it's just not gonna work anyways whoo hopefully i was recording because if i have to go through and do that all again i'm gonna be so pissed anyway if you want if you like this video thumbs up if you didn't thumbs down if you really like more of this nonsense give us a subscribe and hit that little notification icon bell thing i'm a jigger um and we'll see you next time thanks for watching this nonsense we'll see you next time