Java the bash, to interpret and execute what it is you want. And we'll see how it goes about doing this. So from my desktop of Kali, I'm just going to go to places. Now I'm going to open up computer. This is the root of our Kali machine. We can now open up the bin folder.
And inside the bin folder, we will find the bash. Since bash is also located in the same folder with all of the default utilities that are used by Kali, it's very easy for it to launch and execute any command that we type in, such as nano editor, if I want to launch the nano editor, and I tell bash that hey, launch the nano editor for me, it doesn't have to look for it. It's in the same folder, where it's located the bin folder. So now if I open up the nano text editor, and I create a script and I save it, it makes it very Easy for bash to be able to find and launch that script because it will be located in the same directory. So far we have talked about how the command line uses the bash shell as its interpreter. So when I type in something into the CLR command, and that command is correct, bash will know how to execute it.
But if that command is not in the bin folder, where the bash interpreter is located, it will not know what to do and that's why it returns some type of error message saying that the command the bash command was not found, because it was not inside of the bin folder. So let's see how this works. So if I type in Echo, and echo is a built in command in the bash shell that writes its arguments to standard output. So whatever is I write, that follows the word echo or the command echo will be repeated onto the screen. Let's see how this works. Command Prompt I've typed in the word or the command echo followed up by space.
And in quotes. I've typed in hello world. Now when I hit Enter, notice that whatever it is I typed inside of the quotes that follows the command echo is repeated to me or shown to me on the screen. The bash shell knows how to handle the command echo because it's in the same folder, where it's located the bin folder, we're now ready to proceed on with writing our first script and to do this, we're going to use the nano text editor. I don't have to type in the path to the nano text editor because the bash shell will see it in the same folder where it resides the bin folder. So if I type in nano, followed by the name of the script, we're going to call this test.sh.
Sh is the extension used for all bash scripts. So now when I hit Enter, I get a clean text file opened up inside of nano. This is my nano hex editor, and this is a file called test.sh. It is blank right now, but we're going to type in some commands and we're going to make our first script. Every script begins with a shebang. And that is this beginning right here.
The pound sign, exclamation mark is the shebang. And this tells the script, what shell interpreter to use, and it's telling it that hey, your command line interpreter is located inside of the bin directory, and it is the bash shell interpreter. We're now ready to type in our first script. So we're going to start off with that shebang at the top to tell it which command line interpreter to use and we want to use bash and we told it, it's located in the bin folder at the root of this computer. On the next line. We're going to type in echo space, in quotes, hello world.
Close the quote and on the next line, we're going to type in sleep Space five. And that means wait five seconds to respond. On the next slide, we're going to type in echo space. And in quotes, how is the lab so far question mark, close the quote. And now we're going to save this script, and then we'll launch it. To Save this script, we're just going to type in Ctrl x, and we're going to type in Y for yes, and then we're going to hit Enter, and we're back to our command prompt.
A script or a text is just that until we make it an executable. To do that, we have to change the permission. So we use the change mod space plus x command to make the test.sh file and executable. We do this with any script file that we create. Go ahead and hit enter. Notice that it comes right back to the prompt letting us know that our command completed successfully By default, the test sh script was saved to the root of our computer, where the bash shell and the nano editor are also located.
So we're going to type in dot backslash test.sh. And now we just have to hit Enter. And it says hello world. It's going to wait five seconds. And it's going to ask us a question. How is the lab so far, another useful command is the clear command.
And if I type that in, it clears the screen. So we can add this word to our script or this command to our script. And when the script runs, before it does anything else, it will clear the screen. So let's go ahead and bring up our command that launches nano so that we can edit our test.sh. So I'm using my up arrow, refine that command, and there it is. I'm gonna hit enter.
Now, you'll notice that my command prompt is at the beginning of the shebang. To bring it down in one line, I just use my down arrow, and I can hit enter. Now I have a space right between it and the next command. So I'm going to type in the word clear and now Going to launch that clear command when the script runs. Now, we can change the hello world to Hello, your name. So I'm going to use my Down Arrow one more time, use my right arrow all the way over to that parentheses and I'm going to change this to my name.
And I'm now going to use the down arrow one more time. Let's change the sleep number from five to two. I'm gonna come down one more line. And then one more line. Now I'm going to type in read and I want the script to read more