Batch 87 Array Index

John Hammond · Intermediate ·🔐 Cybersecurity ·14y ago

Key Takeaways

The video demonstrates how to create a batch script called "array index" that returns the index or position of a value inside an array, with optional parameters for the array name, find string, return variable, and position.

Full Transcript

hey what's up guys rudolph here coming back at you with another batch tutorial and you know we've been looking at a race just recently and we're going to keep doing that right now keep pounding the pressure on the arrays and making some pretty cool programming stuff programs that's that's the word that i wanted to say but i was so excited i didn't even end up saying it yeah westside you know all right so uh let's get cmd ready to rock because i know i'm ready to rock i don't know about you guys but i'm pumped i'm excited we're just done the batch tutorials that's awesome okay let's go ahead and save this as add echo off no let's not let's call it array what is it what is it what do i want to call this what should i call this array index yeah i think it's array index array index.bat perfect now what array index will do or does or is going to do whatever you'd like however you'd like to say it will return the index or the position where we find um one value inside of the array so we'll need the array uh name itself we'll we'll need what we're trying to find we'll need to return and then of course we will need a position because we want to be able to make it optional or at least we want to make it decide whether or not we should start from a certain position or just go from the beginning so we're going to want to start by actually getting the the find string create string fine that can equal the second argument that we passed with because that's what it is and set position position is actually going to equal the fourth argument but we're immediately going to test right after it if the value of the position if that's equal to nothing so if they haven't actually passed anything in for the position then position can equal zero and if not then we don't have to worry about it but we also are going to want to set our return variable to equal negative one by default so on the off chance we don't find anything we can go ahead and just like say yeah we don't know where it is man go away come back another time and that's all there is to it but we are going to need a limit because we're going to be looping of course so we'll say the length of our array subtract one and then we'll begin the loop so four dash l g in now remember we're going to start from a certain position it's usually by default zero but of course we can modify that we'll increment by one and we'll go up until our limit then we'll do and we can go ahead and test with the conditional statement if the current position that we're at inside of the array if that's equal to what we're looking for or our find thing you know our variable here what we can actually do is go ahead and set our return statement or our return value to equal the current position and then we'll break out of the loop so we'll go to the end and we can go ahead and create end right down at the bottom here and we should be set to go alright let's go ahead and test this out if i were to create a script this is just a typical you know normal script we're working in every day i'll create my main function as usual local okay let's go ahead and create an array i think i'll say um array i think i'll have it say i am really hungry because you know i'm pretty hungry right now it's almost dinner time though i'm out getting pizza pretty soon that's cool all right now we're going to go ahead and call all right index pass in the array and let's say we're looking for i and the return can equal return we can echo out return now let's run our script oh and we had a problem what's going on here create string find uh oh it looks like it's probably over here yep yeah okay i forgot a limiter here sorry about that guys make sure you use a space or whatever you'd like to use and we can go ahead and say script and uh zero because it does not find it anywhere in fact i'm just kidding zero is the first position inside of our array remember because our computer starts counting array indexes at zero and then goes up you know zero one two three four that sort of thing so when we get zero that means it really is at position zero now if i was looking for am we get it at one what if i were looking for hungry that's a three and if we were to look for let's say food ah what do we get here negative one so it's not actually inside the script it's not inside the array anyway but there you go guys it's very simple very easy i'm sorry about the mess-ups there really it's not that big of a deal just uh just go make something now that's gonna find nothing because you know it's not gonna find anything that's that's as simple as it gets guys thank you very much though and i will see you in the next tutorial before i go though let's go actually go ahead and put this inside of our system path so array index we can go ahead and copy that and put it into our tools and i'll cut it and go ahead and put it into our system path see windows system 32 plop it right in there and we're ready to rock okay thank you very much guys uh please like the video if you enjoyed it please leave a comment if you would like to share some input and feedback that'd be really fantastic i'd love to know what you're thinking and maybe subscribe i don't know it's whatever you guys do but uh thanks again bye

Original Description

If you would like to support me, please like, comment & subscribe, and check me out on Patreon: https://patreon.com/johnhammond010 E-mail: johnhammond010@gmail.com PayPal: http://paypal.me/johnhammond010 GitHub: https://github.com/JohnHammond Site: http://www.johnhammond.org Twitter: https://twitter.com/_johnhammond
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from John Hammond · John Hammond · 13 of 60

1 Code Commentaries? PHP to JavaScript in Bash and PHP!
Code Commentaries? PHP to JavaScript in Bash and PHP!
John Hammond
2 Tutorials? MySQL connection with PHP and Bash!
Tutorials? MySQL connection with PHP and Bash!
John Hammond
3 Variable Naming in Python! Happy Birthday, Linux! Nokia N900!
Variable Naming in Python! Happy Birthday, Linux! Nokia N900!
John Hammond
4 JavaScript Splits The URL!
JavaScript Splits The URL!
John Hammond
5 HTML Tables in Python!
HTML Tables in Python!
John Hammond
6 HTML, Net Shares, GML!
HTML, Net Shares, GML!
John Hammond
7 Python 08 Programming Style and Comments
Python 08 Programming Style and Comments
John Hammond
8 Python 26 Object Oriented Programming
Python 26 Object Oriented Programming
John Hammond
9 75 Python Tutorials, Out Now!
75 Python Tutorials, Out Now!
John Hammond
10 Batch 14 Mathematical Expressions
Batch 14 Mathematical Expressions
John Hammond
11 Batch 85 Array Append
Batch 85 Array Append
John Hammond
12 Batch 86 Array Count
Batch 86 Array Count
John Hammond
Batch 87 Array Index
Batch 87 Array Index
John Hammond
14 Batch 88 Array Insert
Batch 88 Array Insert
John Hammond
15 Batch 89 Array Remove
Batch 89 Array Remove
John Hammond
16 Batch 90 Array Reverse
Batch 90 Array Reverse
John Hammond
17 Python [colorama] 00 Installing on Linux
Python [colorama] 00 Installing on Linux
John Hammond
18 Python [colorama] 09 Cursor Position
Python [colorama] 09 Cursor Position
John Hammond
19 Python [hashlib] 02 Algorithms
Python [hashlib] 02 Algorithms
John Hammond
20 Python 00 Installing IDLE on Linux
Python 00 Installing IDLE on Linux
John Hammond
21 Python [pygame] 11 Rectangular Collision Detection
Python [pygame] 11 Rectangular Collision Detection
John Hammond
22 Python [pygame] 12 Platforming Rectangular Collision Resolution
Python [pygame] 12 Platforming Rectangular Collision Resolution
John Hammond
23 Python [XML-RPC] 01 Research
Python [XML-RPC] 01 Research
John Hammond
24 Python [pyenchant] 03 Personal Word Lists
Python [pyenchant] 03 Personal Word Lists
John Hammond
25 FancyURLopener Authentication and User-Agent [urllib] 03
FancyURLopener Authentication and User-Agent [urllib] 03
John Hammond
26 Python 04: PEP8 Coding
Python 04: PEP8 Coding
John Hammond
27 Python Challenge! 17 COOKIES
Python Challenge! 17 COOKIES
John Hammond
28 Google CTF 2016: Ernst Echidna
Google CTF 2016: Ernst Echidna
John Hammond
29 Google CTF 2016: Spotted Quoll
Google CTF 2016: Spotted Quoll
John Hammond
30 Google CTF 2016: Can you Repo It?
Google CTF 2016: Can you Repo It?
John Hammond
31 Google CTF 2016: No Big Deal
Google CTF 2016: No Big Deal
John Hammond
32 Google CTF 2016: In Recorded Conversation
Google CTF 2016: In Recorded Conversation
John Hammond
33 Homemade CTF Challenge: 01 "Orchestra"
Homemade CTF Challenge: 01 "Orchestra"
John Hammond
34 Homemade CTF Challenge: 02 "Bae's Base"
Homemade CTF Challenge: 02 "Bae's Base"
John Hammond
35 Homemade CTF Challenge: 03 "Web Hunt"
Homemade CTF Challenge: 03 "Web Hunt"
John Hammond
36 Homemade CTF Challenge: 04 "UPX"
Homemade CTF Challenge: 04 "UPX"
John Hammond
37 Homemade CTF Challenge: 05 "The Assumption Song"
Homemade CTF Challenge: 05 "The Assumption Song"
John Hammond
38 Homemade CTF Challenge: 06 "A Brisk Stroll"
Homemade CTF Challenge: 06 "A Brisk Stroll"
John Hammond
39 Homemade CTF Challenge: 06 "I lost my password!"
Homemade CTF Challenge: 06 "I lost my password!"
John Hammond
40 web25 :: Mr. Robot : EKOPARTY CTF 2016
web25 :: Mr. Robot : EKOPARTY CTF 2016
John Hammond
41 web50 : RFC 7230 :: EKOPARTY CTF 2016
web50 : RFC 7230 :: EKOPARTY CTF 2016
John Hammond
42 misc50 : Hidden inside EKO :: EKOPARTY CTF 2016
misc50 : Hidden inside EKO :: EKOPARTY CTF 2016
John Hammond
43 Hack The Vote 2016 CTF: Sander's Fan Club [web100]
Hack The Vote 2016 CTF: Sander's Fan Club [web100]
John Hammond
44 Hack The Vote 2016 CTF Warpspeed [forensics150]
Hack The Vote 2016 CTF Warpspeed [forensics150]
John Hammond
45 Juniors CTF 2016 :: Black Suprematic Square
Juniors CTF 2016 :: Black Suprematic Square
John Hammond
46 Juniors CTF 2016 :: Six Strange Tales
Juniors CTF 2016 :: Six Strange Tales
John Hammond
47 Juniors CTF 2016 :: Lost Code
Juniors CTF 2016 :: Lost Code
John Hammond
48 Juniors CTF 2016 :: Here Goes!
Juniors CTF 2016 :: Here Goes!
John Hammond
49 Juniors CTF 2016 :: Southern Cross
Juniors CTF 2016 :: Southern Cross
John Hammond
50 Juniors CTF 2016 :: Clone Attack
Juniors CTF 2016 :: Clone Attack
John Hammond
51 Juniors CTF 2016 :: Dirty Repo
Juniors CTF 2016 :: Dirty Repo
John Hammond
52 Juniors CTF 2016 :: Hackers Blog
Juniors CTF 2016 :: Hackers Blog
John Hammond
53 Juniors CTF 2016 :: Voting!!!
Juniors CTF 2016 :: Voting!!!
John Hammond
54 Juniors CTF 2016 :: The Good, The Bad and The Junkman
Juniors CTF 2016 :: The Good, The Bad and The Junkman
John Hammond
55 Juniors CTF 2016 :: Stop Thief!
Juniors CTF 2016 :: Stop Thief!
John Hammond
56 Juniors CTF 2016 :: ROFL
Juniors CTF 2016 :: ROFL
John Hammond
57 Juniors CTF 2016 :: Restriced Area
Juniors CTF 2016 :: Restriced Area
John Hammond
58 Juniors CTF 2016 :: Oh SSH!
Juniors CTF 2016 :: Oh SSH!
John Hammond
59 HackCon CTF 2017 TRIVIA and BONUS Challenges
HackCon CTF 2017 TRIVIA and BONUS Challenges
John Hammond
60 HackCon CTF 2017 "Bacche" Challenges
HackCon CTF 2017 "Bacche" Challenges
John Hammond

This video teaches how to create a batch script to find the index of a value in an array, with optional parameters, and demonstrates how to use cmd to execute and test the script.

Key Takeaways
  1. Create a new batch script called "array index"
  2. Set the array name, find string, return variable, and position as parameters
  3. Use a loop to iterate through the array and find the index of the value
  4. Test the script using cmd and verify the results
  5. Add the script to the system path for easy execution
💡 The script uses a loop to iterate through the array and find the index of the value, and the system path can be used to execute the script easily.

Related Reads

Up next
Google Did The Impossible
Boot dev
Watch →