Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is Linux's shell scripting language?

2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

In this issue, the editor will bring you about what the shell scripting language of Linux is. The article is rich in content and analyzes and describes it from a professional point of view. I hope you can get something after reading this article.

Shell is the software that "provides a user interface" in the operating system. It is packaged outside the linux kernel and provides an interface for the interaction between the user and the kernel. The commands in the system are explained by shell, and the shell receives the output of the system response and displays it on the screen.

Introduction to 1.shell

Interpretive languages-shell scripts, python, are inefficient and are basically only applicable within the enterprise.

Shell-- script, which records the system relationship between system commands and command execution, and acts as an interpreter.

Gcc-Compiler

Vim-Editor #! / bin/bash magic number, specify interpreter #! / usr/bin/env bash automatic matching interpreter

Descriptive language-C language, java, with high execution efficiency

1. Invocation of script

Script (usually ends with .sh):

[root@desktop5 mnt] # vim westos.sh#!/bin/bash echo hello westos

Method 1: no execution permission, call with sh

[root@desktop5 mnt] # sh westos.sh

Method 2: if you have the permission to execute, call it with absolute path

[root@desktop5 mnt] # chmod + x westos.sh [root@desktop5 mnt] # / mnt/westos.sh

two。 Check of script

+ means: perform an action

None + means: action output

Method 1:

[root@desktop5 mnt] # sh-x / mnt/westos.sh

Method 2:

[root@desktop5 mnt] # vim westos.shemaking Universe Binder Bash-xecho hello westos

Experiment 1: the shortcut key F4 performs filling

Method 1:

[root@desktop5 mnt] # vim / etc/vimrc map ms:call WESTOS () 's # # ms: when executing a command Do not prompt for function WESTOS () call append (0, "# #") call append (1, "# Author: Hao #") call append (2, "# Mail: Hao@westos.com #") call append (3 "# Version: 1. 0 #") call append (4, "# Create_Time:" .strftime ("% Y-%m-%d"). "#") # # time update call append (5, "# Description: #") call append (6 "# #") endfunction

Method 2: make use of. To take over the rest #

Map ms:call WESTOS () 'sfunction WESTOS () call append (0, "# #") call append (1, "# Author: Hao". ("#") call append (2, "# Mail: Hao@westos.com". ("#") call append (3 "# Version: 1. (" # ") call append (4," # Create_Time: ".strftime ("% Y-%m-%d "). (" # ") call append (5," # Description: ". (" # ") call append (6 "# #") endfunction

Test:

[root@desktop5 mnt] # vim westos.sh # # press' F4' to perform fill

Experiment 2: automatically populate when you create a new vim file ending in .sh

Note: old files are not automatically populated

Method 1:

[root@desktop5 mnt] # vim / etc/vimrc autocmd BufNewFile * .sh exec ": call WESTOS ()" # # New file, ending with .sh, execute Call the file "map ms:call WESTOS () 's # # this line comment, in this" table comment function WESTOS () call append (0, "# #") call append (1, "# Author: Hao #") call append (2 "# Mail: Hao@westos.com #") call append (3, "# Version: 1. 0 #") call append (4, "# Create_Time:" .strftime ("% Y-%m-%d"). "#") call append (5, "# Description: #") call append (6 "# #") call append (7, ") call append (8," #! / bin/bash ") endfunction

Method 2:

[root@desktop5 mnt] # vim / etc/vimrc autocmd BufNewFile * .sh exec ": call WESTOS ()"map ms:call WESTOS () 'sfunction WESTOS () call append (0," # # ") call append (1," # Author: Hao ". (" # ") call append (2 "# Mail: Hao@westos.com". ("#") call append (3, "# Version: 1.0". ("#") call append (4, "# Create_Time:" .strftime ("% Y-%m-%d"). ("#") call append (5 "# Description:". ("#") call append (6, "#") call append (7, ") call append (8," #! / bin/bash ") endfunction

Test:

[root@desktop5 mnt] # vim file1.sh # # create a new file ending with .sh and automatically populate the 2.shell script exercise

Exercise 1: display the current host ip address

[root@desktop5 mnt] # vim IPTV show.shemake inet Binder Basifconfig eth0 | awk-F "'/ inet / {print $2}'# # line, separated by spaces, the second character

Test:

[root@desktop5 mnt] # sh ip_show.sh

Exercise 2: show the users in the current host who can log in to the system

[root@desktop5 mnt] # vim username show.shrowxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx / / bash$/ {print $1}'/ etc/passwd # # end with bash and print out the first character.

Test:

Exercise 3: after executing the order, you can clear the air until

Method 1:

[root@desktop5 mnt] # vim clearances log.shroud ClearinBash > / var/log/messages

Method 2:

[root@desktop5 mnt] # vim clearheads log.shemale raceme binds bashecho "" > / var/log/messages

Test:

[root@desktop5 mnt] # chmod + x clear_log.sh [root@desktop5 mnt] # / mnt/clear_log.sh

This is what the editor shares with you about Linux's shell scripting language. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report