1. Shell basic advanced series of articles

Shell basic advanced series of articles

Contents
Chapter 1 The essence of the shell
Chapter 2 shell2
Chapter 3 shell3



foreword

Understanding of the shell


1. Shell basics

1. The essence of shell script

The shell is an interpreted language, which is different from a compiled language like C.

2. The basic steps of shell compilation

The basic process is divided into three steps:
step1, create a shell file,
a text file containing any number of lines of operating system commands or shell commands;
step2, give the shell file execution permission
and use the chmod command to modify the permission;
step3, execute the shell file and
directly call the shell program on the command line ;

2.1 Case 1

step1, create a shell file

chance@ubuntu:~$ mkdir shell_exp
chance@ubuntu:~$ cd shell_exp/
chance@ubuntu:~/shell_exp$ ls
chance@ubuntu:~/shell_exp$ mkdir 1_shell
chance@ubuntu:~/shell_exp$ cd 1_shell/
chance@ubuntu:~/shell_exp/1_shell$ ls
chance@ubuntu:~/shell_exp/1_shell$ touch prog1.sh
chance@ubuntu:~/shell_exp/1_shell$ ls
prog1.sh
chance@ubuntu:~/shell_exp/1_shell$ vim prog1.sh 
chance@ubuntu:~/shell_exp/1_shell$ cat prog1.sh 
date
chance@ubuntu:~/shell_exp/1_shell$ 

step2, grant execution permission

chance@ubuntu:~/shell_exp/1_shell$ chmod 740 prog1.sh 

step3, execute

chance@ubuntu:~/shell_exp/1_shell$ ./prog1.sh 
Wed Mar 30 09:09:14 PDT 2022

2.2 Case 2

Update the prog1.sh file:

chance@ubuntu:~/shell_exp/1_shell$ vim prog1.sh 

Enter the following:
insert image description here

implement

chance@ubuntu:~/shell_exp/1_shell$ ./prog1.sh 
Wed Mar 30 09:11:14 PDT 2022
ubuntu
prog1.sh
ens33     Link encap:Ethernet  HWaddr 00:0c:29:ad:ab:d9  
          inet addr:192.168.93.129  Bcast:192.168.93.255  Mask:255.255.255.0
          inet6 addr: fe80::382e:a0c:baaf:3bd8/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:277481 errors:0 dropped:0 overruns:0 frame:0
          TX packets:116846 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:375502144 (375.5 MB)  TX bytes:7125102 (7.1 MB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:53364 errors:0 dropped:0 overruns:0 frame:0
          TX packets:53364 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1 
          RX bytes:3954711 (3.9 MB)  TX bytes:3954711 (3.9 MB)

chance@ubuntu:~/shell_exp/1_shell$ 

Guess you like

Origin blog.csdn.net/yechen1/article/details/123860573