Video - Introduction to BASH Scripting

7 minutes
Share the link to this page
You need to have access to the item to view this lesson.
One-time Fee
List Price:  $139.99
You save:  $40
List Price:  €128.68
You save:  €36.77
List Price:  £109.54
You save:  £31.30
List Price:  CA$190.78
You save:  CA$54.51
List Price:  A$210.13
You save:  A$60.04
List Price:  S$188.67
You save:  S$53.91
List Price:  HK$1,093.43
You save:  HK$312.43
CHF 91.06
List Price:  CHF 127.49
You save:  CHF 36.43
NOK kr1,048.21
List Price:  NOK kr1,467.54
You save:  NOK kr419.32
DKK kr685.84
List Price:  DKK kr960.21
You save:  DKK kr274.36
List Price:  NZ$227.27
You save:  NZ$64.94
List Price:  د.إ514.17
You save:  د.إ146.91
List Price:  ৳16,424.23
You save:  ৳4,692.97
List Price:  ₹11,645.13
You save:  ₹3,327.42
List Price:  RM657.08
You save:  RM187.75
List Price:  ₦207,529.57
You save:  ₦59,298.40
List Price:  ₨38,952.22
You save:  ₨11,130
List Price:  ฿5,128.60
You save:  ฿1,465.42
List Price:  ₺4,505.02
You save:  ₺1,287.24
List Price:  B$724.25
You save:  B$206.94
List Price:  R2,573.66
You save:  R735.38
List Price:  Лв251.69
You save:  Лв71.91
List Price:  ₩190,221.90
You save:  ₩54,352.99
List Price:  ₪514.66
You save:  ₪147.05
List Price:  ₱8,117.95
You save:  ₱2,319.58
List Price:  ¥21,959.69
You save:  ¥6,274.64
List Price:  MX$2,335.27
You save:  MX$667.26
List Price:  QR510.23
You save:  QR145.79
List Price:  P1,900.42
You save:  P543.01
List Price:  KSh18,548.67
You save:  KSh5,300
List Price:  E£6,650.92
You save:  E£1,900.40
List Price:  ብር7,982.28
You save:  ብር2,280.81
List Price:  Kz119,249.08
You save:  Kz34,073.60
List Price:  CLP$126,219.94
You save:  CLP$36,065.41
List Price:  CN¥995.23
You save:  CN¥284.37
List Price:  RD$8,242.58
You save:  RD$2,355.19
List Price:  DA18,832.24
You save:  DA5,381.02
List Price:  FJ$311.92
You save:  FJ$89.12
List Price:  Q1,087.21
You save:  Q310.65
List Price:  GY$29,298.72
You save:  GY$8,371.66
ISK kr13,742.62
List Price:  ISK kr19,240.22
You save:  ISK kr5,497.60
List Price:  DH1,389.84
You save:  DH397.12
List Price:  L2,479.24
You save:  L708.40
List Price:  ден7,928.70
You save:  ден2,265.50
List Price:  MOP$1,125.76
You save:  MOP$321.67
List Price:  N$2,570.81
You save:  N$734.57
List Price:  C$5,151.79
You save:  C$1,472.04
List Price:  रु18,606.57
You save:  रु5,316.54
List Price:  S/523.93
You save:  S/149.70
List Price:  K544.26
You save:  K155.51
List Price:  SAR525.04
You save:  SAR150.02
List Price:  ZK3,747.57
You save:  ZK1,070.81
List Price:  L640.31
You save:  L182.96
List Price:  Kč3,172.88
You save:  Kč906.60
List Price:  Ft49,368.78
You save:  Ft14,106.37
SEK kr1,053.51
List Price:  SEK kr1,474.96
You save:  SEK kr421.44
List Price:  ARS$125,081.06
You save:  ARS$35,740
List Price:  Bs967.13
You save:  Bs276.34
List Price:  COP$541,644.74
You save:  COP$154,766.69
List Price:  ₡71,976.06
You save:  ₡20,566.05
List Price:  L3,458.74
You save:  L988.28
List Price:  ₲1,052,935.89
You save:  ₲300,860.31
List Price:  $U5,389.29
You save:  $U1,539.90
List Price:  zł547.24
You save:  zł156.36
Already have an account? Log In


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

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 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 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 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 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

Sign Up


Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.