SoFunction
Updated on 2025-04-08

Detailed explanation of the classification example of Shell command interpreter

Shell command interpreter: between the system kernel—>Command interpreter—>Peripheral application: Application/Command/Service

Shell programming: bash programming

1. Command interpreter

bash The most widely used command interpreter at present, Red Hat series (default), Debain, Unbantu, BASH full name: Bourne-Again Shell
dash Generally, the default Debain/Unbantu system is used, and it is recommended to use bash when running scripts.
csh,tcsh Some Unix systems use
zsh More features and more plug-ins to look better

2. Programming language classification

Analysis: Direct parsing After writing the code, the shell, python, run it through the corresponding parser
Compilation: Need to be compiled and run C,C++

Explanation

[root@localhost ~]# vim 
[root@localhost ~]# cat 
                    print("hrllo world!")
[root@localhost ~]# python 
                    hrllo world!

3. Shell script execution method

1Execute via sh or bash

[root@localhost shell]# vim 
[root@localhost shell]# cat  
hostname
pwd
whoami
[root@localhost shell]# sh  

/root/shell
root
[root@localhost shell]# bash  

/root/shell
root
[root@localhost shell]# ll `which sh bash`
-rwxr-xr-x. 1 root root 964544 Apr 10  2018 /usr/bin/bash
lrwxrwxrwx. 1 root root      4 Mar 23 05:59 /usr/bin/sh -> bash

2Execute via source or .

[root@localhost shell]# .  

/root/shell
root
[root@localhost shell]# source  

/root/shell
root

3 Execute through absolute or relative paths

[root@localhost shell]# ./
-bash: ./: Permission denied
[root@localhost shell]# chmod +x ./ 
[root@localhost shell]# ls -l
total 4
-rwxr-xr-x. 1 root root 21 May  6 01:15 
[root@localhost shell]# ./

/root/shell
root

4 Run by redirection symbol

[root@localhost shell]# sh <  

/root/shell
root
[root@localhost shell]# bash <  

/root/shell
root

4. Application scenarios

Applications and scenarios

Execute via sh or bash The most common way to write scripts is in other non-Red Hat systems. It is recommended to use bash to run scripts
By.or source Loading/configuring effective files (environment variables, alias) can be used to implement include function, and eight other scripts are referenced to the current script.
By relative or absolute path This is generally not recommended, system scripts/services use scripts (plus execution permissions)
Enter a redirector Not recommended

Summarize