1 00:00:00,000 --> 00:00:04,200 [Intro Music] 2 00:00:04,259 --> 00:00:06,059 We have just successfully created 3 00:00:06,089 --> 00:00:07,919 a new executable script called 4 00:00:07,949 --> 00:00:11,339 script.sh. And we have successfully 5 00:00:11,399 --> 00:00:13,859 executed it using the absolute or 6 00:00:13,859 --> 00:00:16,289 relative path to location of this 7 00:00:16,289 --> 00:00:17,909 script. Here are three different 8 00:00:17,909 --> 00:00:19,769 examples for execution of this 9 00:00:19,769 --> 00:00:21,899 script. But we are not able to 10 00:00:21,899 --> 00:00:24,449 access it like this. And if you 11 00:00:24,449 --> 00:00:26,669 want to do so you need to modify 12 00:00:26,819 --> 00:00:29,069 PATH variable. But first, let's 13 00:00:29,069 --> 00:00:31,499 create a new subfolder in the home 14 00:00:31,499 --> 00:00:33,238 directory for this user, 'bogdan' 15 00:00:33,238 --> 00:00:35,669 user. And inside of it, we will 16 00:00:35,669 --> 00:00:38,009 place this script file and 17 00:00:38,009 --> 00:00:39,959 afterwards we will add path to 18 00:00:39,959 --> 00:00:42,149 this 'bin' folder, to this PATH 19 00:00:42,149 --> 00:00:44,429 variable. Let's do that. Let's 20 00:00:44,429 --> 00:00:46,679 first create a new folder called 21 00:00:46,709 --> 00:00:49,199 'bin' here in home directory for this 22 00:00:49,199 --> 00:00:51,659 user. And here I see this folder. 23 00:00:51,989 --> 00:00:54,929 And now let's move this script.sh 24 00:00:54,929 --> 00:00:57,629 file into this 'bin' folder. For that 25 00:00:57,659 --> 00:01:00,089 I'll use command 'mv', and move 26 00:01:00,119 --> 00:01:05,188 'script.sh' to 'bin/script.sh'. Like 27 00:01:05,188 --> 00:01:07,589 so. And now if I list the contents 28 00:01:07,619 --> 00:01:10,349 of the 'bin' folder, I'll see script.sh 29 00:01:10,349 --> 00:01:13,109 file here inside. Let's 'cd' to 30 00:01:13,109 --> 00:01:16,889 'bin', and here type 'pwd', print 31 00:01:16,919 --> 00:01:19,409 working directory. And I see the full 32 00:01:19,439 --> 00:01:22,199 path to 'bin' folder. And now I 33 00:01:22,199 --> 00:01:24,719 need to take this path, and 34 00:01:24,749 --> 00:01:26,969 concatenate it to this PATH 35 00:01:27,029 --> 00:01:30,089 variable. For that you need to do 36 00:01:30,089 --> 00:01:31,739 following. Let's first copy 37 00:01:31,739 --> 00:01:34,319 this section; and next type following 38 00:01:34,319 --> 00:01:38,219 command, 'export PATH = 39 00:01:38,249 --> 00:01:41,939 $PATH', next ':', and 40 00:01:41,969 --> 00:01:44,369 let's now paste copied path to 41 00:01:44,369 --> 00:01:46,859 'bin' folder. What this command 42 00:01:46,889 --> 00:01:49,859 will do? It will take existing PATH 43 00:01:49,889 --> 00:01:52,979 variable and concatenate to it this 44 00:01:53,009 --> 00:01:55,319 section. Please don't forget to add 45 00:01:55,319 --> 00:01:57,779 here ':'. And afterwards, this 46 00:01:57,779 --> 00:02:00,359 resulting path will be exported 47 00:02:00,599 --> 00:02:03,509 into PATH variable. And technically 48 00:02:03,539 --> 00:02:06,179 we will rewrite existing PATH 49 00:02:06,209 --> 00:02:09,149 variable. Let's try to press Enter 50 00:02:09,149 --> 00:02:11,339 and see what will happen. Let's use 51 00:02:11,369 --> 00:02:13,919 'echo', and type now PATH variable. 52 00:02:14,309 --> 00:02:16,919 And now I see that this section was 53 00:02:16,949 --> 00:02:19,139 concatenated to previous PATH 54 00:02:19,199 --> 00:02:22,589 variable. And now I am able to 55 00:02:22,589 --> 00:02:24,689 execute that script that is located 56 00:02:24,689 --> 00:02:26,459 inside of the 'bin' folder here in 57 00:02:26,459 --> 00:02:28,065 home user directory for 'bogdan' 58 00:02:28,065 --> 00:02:30,929 user anywhere I want. Let's 59 00:02:30,929 --> 00:02:32,909 try to do that for example, here in 60 00:02:32,909 --> 00:02:36,269 'bin' folder type simply 'script.sh' 61 00:02:36,449 --> 00:02:38,429 without any prefixes, without 62 00:02:38,429 --> 00:02:41,009 any path, like so. Let's press Enter, 63 00:02:41,039 --> 00:02:43,139 and I see result. Script was 64 00:02:43,169 --> 00:02:45,569 executed successfully. 'Hello from 65 00:02:45,569 --> 00:02:48,119 the custom script'. I could 'cd' for 66 00:02:48,119 --> 00:02:50,999 example to root directory like so, 67 00:02:50,999 --> 00:02:53,999 and enter the same command 'script.sh', 68 00:02:54,029 --> 00:02:55,589 and the result will be the same. 69 00:02:56,129 --> 00:02:57,749 And the reason for that is that now 70 00:02:57,779 --> 00:02:59,939 this script is located in the PATH, 71 00:03:00,119 --> 00:03:02,429 here. And I'm able to access it 72 00:03:02,459 --> 00:03:04,859 anywhere I want. And of course, if 73 00:03:04,859 --> 00:03:06,659 you want to, you could even remove 74 00:03:06,659 --> 00:03:08,219 this extension and name the 75 00:03:08,219 --> 00:03:10,649 script without any extension at all. 76 00:03:10,769 --> 00:03:12,929 For example, let's rename it to 77 00:03:12,929 --> 00:03:14,699 let's say, 'my-script' without 78 00:03:14,699 --> 00:03:17,039 extension. Let's use 'mv' command; 79 00:03:17,069 --> 00:03:19,409 and here I need to use absolute or 80 00:03:19,409 --> 00:03:21,689 relative path to this script file, 81 00:03:21,929 --> 00:03:23,789 and let's use the relative path, 82 00:03:23,789 --> 00:03:26,309 home directory, here will be '/bin/ 83 00:03:26,339 --> 00:03:29,579 script.sh', and let's rename it to 84 00:03:29,579 --> 00:03:31,399 '/bin', and here will be simply 85 00:03:31,399 --> 00:03:34,469 'my-script' without any extensions, like 86 00:03:34,469 --> 00:03:37,349 so, Enter. And now let's try to 87 00:03:37,379 --> 00:03:39,809 execute this my-script. Simply type 88 00:03:39,809 --> 00:03:43,259 'my-script', and the result is the 89 00:03:43,259 --> 00:03:46,559 same. And if I list the contents of 90 00:03:46,559 --> 00:03:48,869 the 'bin' folder like so. Let me do 91 00:03:48,869 --> 00:03:52,139 that. Let's actually add the '-l' 92 00:03:52,139 --> 00:03:54,929 option. I'll again see that this 93 00:03:54,929 --> 00:03:57,479 file is executable script, it is in 94 00:03:57,479 --> 00:03:59,429 green color. And here I see 95 00:03:59,609 --> 00:04:01,349 executable permissions for a 96 00:04:01,349 --> 00:04:03,899 specific user, for owner of this 97 00:04:03,899 --> 00:04:06,269 file. That's how you could pretty 98 00:04:06,299 --> 00:04:09,269 fast and easily allow execution of 99 00:04:09,299 --> 00:04:11,609 any executable script from anywhere 100 00:04:11,669 --> 00:04:14,429 by adding a path where this script 101 00:04:14,429 --> 00:04:17,159 is located to PATH variable like we 102 00:04:17,189 --> 00:04:20,369 did here. Great. That's all for 103 00:04:20,369 --> 00:04:22,019 this lecture. And this is all actually 104 00:04:22,019 --> 00:04:24,149 about executable scripts and 105 00:04:24,149 --> 00:04:26,309 permissions. I will not show you how to 106 00:04:26,309 --> 00:04:27,988 create more complicated scripts. 107 00:04:28,019 --> 00:04:29,729 And if you want, you could do so. 108 00:04:29,879 --> 00:04:31,439 Actually executable script is 109 00:04:31,439 --> 00:04:33,929 simply a set of shell commands, 110 00:04:33,959 --> 00:04:35,669 nothing else. You are able to 111 00:04:35,669 --> 00:04:37,529 perform any actions you like. You 112 00:04:37,529 --> 00:04:38,789 could create variables, you could 113 00:04:38,819 --> 00:04:41,249 perform any other actions like list 114 00:04:41,249 --> 00:04:42,989 files, grep output of some 115 00:04:42,989 --> 00:04:45,029 commands, and so on. Script is 116 00:04:45,029 --> 00:04:47,249 simply a set of commands that are 117 00:04:47,249 --> 00:04:50,459 executed one by one. All right, 118 00:04:50,519 --> 00:04:52,259 that's all for this subsection. And 119 00:04:52,259 --> 00:04:54,269 next let's talk about networking in 120 00:04:54,299 --> 00:04:56,919 Linux systems. I'll see you next. Bye-Bye. 121 00:04:56,919 --> 00:04:59,797 [no audio]