当前位置:网站首页>Shell programming 01_ Shell foundation
Shell programming 01_ Shell foundation
2022-07-02 10:48:00 【sinat_ thirty-six million seventy thousand four hundred and eig】
Darnay Education
The latest version Linux Shell Full set of scripts , Finally made it clear !
Teacher dingmingyi
shell Programming 01_Shell Basics
shell command need shell command interpreter
common shell Interpreter
/bin/bash
/bin/sh
/bin/csh
/bin/tcsh
Interpreter : Translate user instructions into instructions recognized by the kernel
adopt usermod、chsh You can change the login shell
When creating temporary users , If we don't specify an interpreter ,
The default interpreter is /bin/bash
[email protected]:/home/ubuntu/songweibin/shell# useradd test1
[email protected]:/home/ubuntu/songweibin/shell# grep test1 /etc/passwd
test1:x:1001:1001::/home/test1:/bin/sh
usermod chsh To modify the interpreter
adopt /etc/shells
You can see the support shell Interpreter
[email protected]:/home/ubuntu/songweibin/shell# cat /etc/shells
# /etc/shells: valid login shells
/bin/sh
/bin/bash
/usr/bin/bash
/bin/rbash
/usr/bin/rbash
/bin/dash
/usr/bin/dash
We can also install more shell Interpreter
[email protected]:/home/ubuntu/songweibin/shell# apt-get install tcsh
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
linux-headers-5.11.0-27-generic linux-hwe-5.11-headers-5.11.0-27
linux-image-5.11.0-27-generic linux-modules-5.11.0-27-generic
linux-modules-extra-5.11.0-27-generic
Use 'apt autoremove' to remove them.
The following NEW packages will be installed:
tcsh
0 upgraded, 1 newly installed, 0 to remove and 90 not upgraded.
Need to get 427 kB of archives.
After this operation, 1,363 kB of additional disk space will be used.
Get:1 http://cn.archive.ubuntu.com/ubuntu focal/universe amd64 tcsh amd64 6.21.00-1 [427 kB]
Fetched 427 kB in 7s (61.1 kB/s)
Selecting previously unselected package tcsh.
(Reading database ... 227919 files and directories currently installed.)
Preparing to unpack .../tcsh_6.21.00-1_amd64.deb ...
Unpacking tcsh (6.21.00-1) ...
Setting up tcsh (6.21.00-1) ...
update-alternatives: using /bin/tcsh to provide /bin/csh (csh) in auto mode
Processing triggers for man-db (2.9.1-1) ...
Review the supported shell Interpreter
[email protected]:/home/ubuntu/songweibin/shell# cat /etc/shells
# /etc/shells: valid login shells
/bin/sh
/bin/bash
/usr/bin/bash
/bin/rbash
/usr/bin/rbash
/bin/dash
/usr/bin/dash
/bin/tcsh
/usr/bin/tcsh
test1 The user defaults to shell The interpreter is /bin/bash
Modify the default shell Interpreter method
usermod -s /bin/tcsh test
[email protected]:/home/ubuntu/songweibin/shell# usermod -s /bin/tcsh test1
[email protected]:/home/ubuntu/songweibin/shell# grep test1 /etc/passwd
test1:x:1001:1001::/home/test1:/bin/tcsh
have access to chsh -s /bin/bash test1 Modify user default shell Interpreter
chsh:change shell It means
[email protected]:/home/ubuntu/songweibin/shell# chsh -s /bin/bash test1
[email protected]:/home/ubuntu/songweibin/shell# grep test1 /etc/passwd
test1:x:1001:1001::/home/test1:/bin/bash
Why does the default support /bin/bash Well ?
because Bash Many functions and features
Shortcut key Tab Key completion
Shortcut key :
Ctrl + a The front of the command line
Ctrl + e At the end of the command line
Ctrl + C The currently executed command is revoked
Ctrl + l Clear the screen
Tab Key completion : Command-Line Completion Options can be supplemented
Command history (history)
Read the history through the up and down buttons
Alias of command (aliase)
ll= ls-l
Redirection of standard input and output (>、 >>、2>、2>>、&>、 &>>)
> : Correct information redirection
2>: Wrong message redirection
&>: Both correct information and wrong information
[email protected]:/home/ubuntu/songweibin# ls
42fputcandwrite 84fatherandsoncommunication fl
82testpipe 85brotherscommunication shell
83mypipe 87fileforprocesscommunication test
[email protected]:/home/ubuntu/songweibin# ls > a.txt
[email protected]:/home/ubuntu/songweibin# cat a.txt
42fputcandwrite
82testpipe
83mypipe
84fatherandsoncommunication
85brotherscommunication
87fileforprocesscommunication
a.txt
fl
shell
test
Why do you still have a.txt How about myself ?
ls > a.txt Commands are created first a.txt file
And then ls Enter the results of into a.txt in
If you use two greater than signs , Yes means to add
It is to add content on the basis of the original content
[email protected]:/home/ubuntu/songweibin# ls >>a.txt
[email protected]:/home/ubuntu/songweibin# cat a.txt
42fputcandwrite
82testpipe
83mypipe
84fatherandsoncommunication
85brotherscommunication
87fileforprocesscommunication
a.txt
fl
shell
test
42fputcandwrite
82testpipe
83mypipe
84fatherandsoncommunication
85brotherscommunication
87fileforprocesscommunication
a.txt
fl
shell
test
[email protected]tu-virtual-machine:/home/ubuntu/songweibin#
Use 2> Export the error information to the specified file
[email protected]:/home/ubuntu/songweibin# ls song.txt
ls: cannot access 'song.txt': No such file or directory
[email protected]:/home/ubuntu/songweibin#
Use > Only correct information can be output .
[email protected]:/home/ubuntu/songweibin# ls song.txt > a.txt
ls: cannot access 'song.txt': No such file or directory
[email protected]:/home/ubuntu/songweibin# cat a.txt
Use 2> Export the error information to the specified file
[email protected]:/home/ubuntu/songweibin# ls song.txt 2> a.txt
[email protected]:/home/ubuntu/songweibin# cat a.txt
ls: cannot access 'song.txt': No such file or directory
You can also use &> ( Also recreate the file , Will be covered ) It can output correct and wrong information at the same time
single >: All are re created output files , So it will cover
double >: All are additions
The Conduit (|)
The output of the first command can be used as the input of the second command
Search for installed software :
[email protected]:/home/ubuntu/songweibin# apt-cache search all|grep tcsh
tcsh - TENEX C Shell, an enhanced version of Berkeley csh
[email protected]:/home/ubuntu/songweibin#
apt-get install ksh
Add a new interpreter
[email protected]:/home/ubuntu/songweibin# cat /etc/shells
# /etc/shells: valid login shells
/bin/sh
/bin/bash
/usr/bin/bash
/bin/rbash
/usr/bin/rbash
/bin/dash
/usr/bin/dash
/bin/tcsh
/usr/bin/tcsh
/usr/bin/ksh2020
/usr/bin/rksh2020
adopt ksh Use it directly ksh Interpreter
ksh Only through clear Lai Qingping
Unable to get Ctrl+l
ksh Can't use direction keys So by default /bin/bash
# ^[[C^[[C^[[C^[[C^[[C^[[D^[[D^[[D^[[D^[[A^[[A^[[A^[[B^[[B
ksh adopt exit Return to the last default interpreter
# exit
[email protected]:/home/ubuntu/songweibin#
Shell The manner in which the order is executed
1. Interactive ( Command line )
Artificial intervention
Explain and execute one by one Low efficiency
2. Non interactive ( Script )
It needs to be designed in advance
Batch execution Efficient
边栏推荐
- Test -- Summary of interview questions
- How to get the password of cpolar?
- What is the significance of the college entrance examination
- Introduction to MySQL 8 DBA foundation tutorial
- [visual studio] visual studio 2019 community version cmake development environment installation (download | install relevant components | create compilation execution project | error handling)
- stm32和電機開發(上比特系統)
- 合并有序数列
- SQOOP 1.4.6 INSTALL
- JSP webshell免杀——webshell免杀
- 2021-09-12
猜你喜欢
Flutter环境配置保姆级教程,让doctor一绿到底
flink 提交程序
Ks009 implement pet management system based on SSH
UVM learning - build a simple UVM verification platform
Operator-1 first acquaintance with operator
Flink calculates topn hot list in real time
【TS】1368- 秒懂 TypeScript 泛型工具类型!
Redis set password
07数据导入Sqoop
JS reduce accumulator
随机推荐
PCL之滤波
Operator-1 first acquaintance with operator
(五)APA场景搭建之挡位控制设置
Nonlinear optimization: steepest descent method, Newton method, Gauss Newton method, Levenberg Marquardt method
Pywin32打开指定窗口
Flink实时计算topN热榜
14. Code implementation of semaphore
[unity3d] production progress bar - make image have the functions of filled and sliced at the same time
[unity3d] cannot correctly obtain the attribute value of recttransform, resulting in calculation error
[unity3d] nested use layout group to make scroll view with dynamic sub object height
从MediaRecord录像中读取H264参数
JSP webshell免杀——JSP的基础
Flink calculates topn hot list in real time
PCL 投影点云
使用sqlcipher打开加密的sqlite方法
两数之和,求目标值
面对不确定性,供应链的作用
2021-10-04
长投学堂上面的账户安全吗?
Flink submitter