当前位置:网站首页>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
边栏推荐
- Use WinDbg to statically analyze dump files (summary of practical experience)
- 记录 AttributeError: ‘NoneType‘ object has no attribute ‘nextcall‘
- 使用sqlcipher打开加密的sqlite方法
- flume 190 INSTALL
- 13. Semaphore critical zone protection
- Pytest framework implements pre post
- 14. Code implementation of semaphore
- "Talking about podcasts" vol.352 the age of children: breaking the inner scroll, what can we do before high school?
- 618再次霸榜的秘密何在?耐克最新财报给出答案
- Sus system availability scale
猜你喜欢
Beautiful and intelligent, Haval H6 supreme+ makes Yuanxiao travel safer
Pytest learning --base
《实习报告》Skywalking分布式链路追踪?
shell编程01_Shell基础
Flink submitter
nodejs+express+mysql简单博客搭建
12. Process synchronization and semaphore
Internet News: Tencent conference application market was officially launched; Soul went to Hong Kong to submit the listing application
AI技术产业热点分析
2021-10-02
随机推荐
Session cookies and tokens
LeetCode+ 76 - 80 暴搜专题
Stm32 et développement de moteurs (système supérieur)
[Fantasy 4] introduction and use of UMG components (under update...)
lunix重新分配root 和 home 空间内存
长投学堂上面的账户安全吗?
What are the popular frameworks for swoole in 2022?
Shutter - canvas custom graph
两数之和,求目标值
UWA report uses tips. Did you get it? (the fourth bullet)
"Matching" is true love, a new attitude for young people to make friends
Flutter——Canvas自定义曲线图
Considerations for Apache deploying static web page projects
拆解美图SaaS:开着飞机换引擎
[Lua] summary of common knowledge points (including common interview sites)
网络通信学习
UVM learning - object attribute of UVM phase
Use WinDbg to statically analyze dump files (summary of practical experience)
2021-09-12
2021-10-04